10b57cec5SDimitry Andric// -*- C++ -*- 20b57cec5SDimitry Andric//===-------------------------- utility -----------------------------------===// 30b57cec5SDimitry Andric// 40b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 50b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information. 60b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 70b57cec5SDimitry Andric// 80b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 90b57cec5SDimitry Andric 100b57cec5SDimitry Andric#ifndef _LIBCPP_UTILITY 110b57cec5SDimitry Andric#define _LIBCPP_UTILITY 120b57cec5SDimitry Andric 130b57cec5SDimitry Andric/* 140b57cec5SDimitry Andric utility synopsis 150b57cec5SDimitry Andric 160b57cec5SDimitry Andric#include <initializer_list> 170b57cec5SDimitry Andric 180b57cec5SDimitry Andricnamespace std 190b57cec5SDimitry Andric{ 200b57cec5SDimitry Andric 210b57cec5SDimitry Andrictemplate <class T> 220b57cec5SDimitry Andric void 230b57cec5SDimitry Andric swap(T& a, T& b); 240b57cec5SDimitry Andric 250b57cec5SDimitry Andricnamespace rel_ops 260b57cec5SDimitry Andric{ 270b57cec5SDimitry Andric template<class T> bool operator!=(const T&, const T&); 280b57cec5SDimitry Andric template<class T> bool operator> (const T&, const T&); 290b57cec5SDimitry Andric template<class T> bool operator<=(const T&, const T&); 300b57cec5SDimitry Andric template<class T> bool operator>=(const T&, const T&); 310b57cec5SDimitry Andric} 320b57cec5SDimitry Andric 330b57cec5SDimitry Andrictemplate<class T> 340b57cec5SDimitry Andricvoid 350b57cec5SDimitry Andricswap(T& a, T& b) noexcept(is_nothrow_move_constructible<T>::value && 360b57cec5SDimitry Andric is_nothrow_move_assignable<T>::value); 370b57cec5SDimitry Andric 380b57cec5SDimitry Andrictemplate <class T, size_t N> 390b57cec5SDimitry Andricvoid 400b57cec5SDimitry Andricswap(T (&a)[N], T (&b)[N]) noexcept(noexcept(swap(*a, *b))); 410b57cec5SDimitry Andric 420b57cec5SDimitry Andrictemplate <class T> T&& forward(typename remove_reference<T>::type& t) noexcept; // constexpr in C++14 430b57cec5SDimitry Andrictemplate <class T> T&& forward(typename remove_reference<T>::type&& t) noexcept; // constexpr in C++14 440b57cec5SDimitry Andric 450b57cec5SDimitry Andrictemplate <class T> typename remove_reference<T>::type&& move(T&&) noexcept; // constexpr in C++14 460b57cec5SDimitry Andric 470b57cec5SDimitry Andrictemplate <class T> 480b57cec5SDimitry Andric typename conditional 490b57cec5SDimitry Andric < 500b57cec5SDimitry Andric !is_nothrow_move_constructible<T>::value && is_copy_constructible<T>::value, 510b57cec5SDimitry Andric const T&, 520b57cec5SDimitry Andric T&& 530b57cec5SDimitry Andric >::type 540b57cec5SDimitry Andric move_if_noexcept(T& x) noexcept; // constexpr in C++14 550b57cec5SDimitry Andric 560b57cec5SDimitry Andrictemplate <class T> constexpr add_const_t<T>& as_const(T& t) noexcept; // C++17 570b57cec5SDimitry Andrictemplate <class T> void as_const(const T&&) = delete; // C++17 580b57cec5SDimitry Andric 590b57cec5SDimitry Andrictemplate <class T> typename add_rvalue_reference<T>::type declval() noexcept; 600b57cec5SDimitry Andric 610b57cec5SDimitry Andrictemplate <class T1, class T2> 620b57cec5SDimitry Andricstruct pair 630b57cec5SDimitry Andric{ 640b57cec5SDimitry Andric typedef T1 first_type; 650b57cec5SDimitry Andric typedef T2 second_type; 660b57cec5SDimitry Andric 670b57cec5SDimitry Andric T1 first; 680b57cec5SDimitry Andric T2 second; 690b57cec5SDimitry Andric 700b57cec5SDimitry Andric pair(const pair&) = default; 710b57cec5SDimitry Andric pair(pair&&) = default; 72*e40139ffSDimitry Andric explicit(see-below) constexpr pair(); 73*e40139ffSDimitry Andric explicit(see-below) pair(const T1& x, const T2& y); // constexpr in C++14 74*e40139ffSDimitry Andric template <class U, class V> explicit(see-below) pair(U&& x, V&& y); // constexpr in C++14 75*e40139ffSDimitry Andric template <class U, class V> explicit(see-below) pair(const pair<U, V>& p); // constexpr in C++14 76*e40139ffSDimitry Andric template <class U, class V> explicit(see-below) pair(pair<U, V>&& p); // constexpr in C++14 770b57cec5SDimitry Andric template <class... Args1, class... Args2> 780b57cec5SDimitry Andric pair(piecewise_construct_t, tuple<Args1...> first_args, 790b57cec5SDimitry Andric tuple<Args2...> second_args); 800b57cec5SDimitry Andric 810b57cec5SDimitry Andric template <class U, class V> pair& operator=(const pair<U, V>& p); 820b57cec5SDimitry Andric pair& operator=(pair&& p) noexcept(is_nothrow_move_assignable<T1>::value && 830b57cec5SDimitry Andric is_nothrow_move_assignable<T2>::value); 840b57cec5SDimitry Andric template <class U, class V> pair& operator=(pair<U, V>&& p); 850b57cec5SDimitry Andric 860b57cec5SDimitry Andric void swap(pair& p) noexcept(is_nothrow_swappable_v<T1> && 870b57cec5SDimitry Andric is_nothrow_swappable_v<T2>); 880b57cec5SDimitry Andric}; 890b57cec5SDimitry Andric 900b57cec5SDimitry Andrictemplate <class T1, class T2> bool operator==(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14 910b57cec5SDimitry Andrictemplate <class T1, class T2> bool operator!=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14 920b57cec5SDimitry Andrictemplate <class T1, class T2> bool operator< (const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14 930b57cec5SDimitry Andrictemplate <class T1, class T2> bool operator> (const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14 940b57cec5SDimitry Andrictemplate <class T1, class T2> bool operator>=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14 950b57cec5SDimitry Andrictemplate <class T1, class T2> bool operator<=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14 960b57cec5SDimitry Andric 970b57cec5SDimitry Andrictemplate <class T1, class T2> pair<V1, V2> make_pair(T1&&, T2&&); // constexpr in C++14 980b57cec5SDimitry Andrictemplate <class T1, class T2> 990b57cec5SDimitry Andricvoid 1000b57cec5SDimitry Andricswap(pair<T1, T2>& x, pair<T1, T2>& y) noexcept(noexcept(x.swap(y))); 1010b57cec5SDimitry Andric 102*e40139ffSDimitry Andricstruct piecewise_construct_t { explicit piecewise_construct_t() = default; }; 1030b57cec5SDimitry Andricinline constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t(); 1040b57cec5SDimitry Andric 1050b57cec5SDimitry Andrictemplate <class T> struct tuple_size; 1060b57cec5SDimitry Andrictemplate <size_t I, class T> struct tuple_element; 1070b57cec5SDimitry Andric 1080b57cec5SDimitry Andrictemplate <class T1, class T2> struct tuple_size<pair<T1, T2> >; 1090b57cec5SDimitry Andrictemplate <class T1, class T2> struct tuple_element<0, pair<T1, T2> >; 1100b57cec5SDimitry Andrictemplate <class T1, class T2> struct tuple_element<1, pair<T1, T2> >; 1110b57cec5SDimitry Andric 1120b57cec5SDimitry Andrictemplate<size_t I, class T1, class T2> 1130b57cec5SDimitry Andric typename tuple_element<I, pair<T1, T2> >::type& 1140b57cec5SDimitry Andric get(pair<T1, T2>&) noexcept; // constexpr in C++14 1150b57cec5SDimitry Andric 1160b57cec5SDimitry Andrictemplate<size_t I, class T1, class T2> 1170b57cec5SDimitry Andric const typename tuple_element<I, pair<T1, T2> >::type& 1180b57cec5SDimitry Andric get(const pair<T1, T2>&) noexcept; // constexpr in C++14 1190b57cec5SDimitry Andric 1200b57cec5SDimitry Andrictemplate<size_t I, class T1, class T2> 1210b57cec5SDimitry Andric typename tuple_element<I, pair<T1, T2> >::type&& 1220b57cec5SDimitry Andric get(pair<T1, T2>&&) noexcept; // constexpr in C++14 1230b57cec5SDimitry Andric 1240b57cec5SDimitry Andrictemplate<size_t I, class T1, class T2> 1250b57cec5SDimitry Andric const typename tuple_element<I, pair<T1, T2> >::type&& 1260b57cec5SDimitry Andric get(const pair<T1, T2>&&) noexcept; // constexpr in C++14 1270b57cec5SDimitry Andric 1280b57cec5SDimitry Andrictemplate<class T1, class T2> 1290b57cec5SDimitry Andric constexpr T1& get(pair<T1, T2>&) noexcept; // C++14 1300b57cec5SDimitry Andric 1310b57cec5SDimitry Andrictemplate<class T1, class T2> 1320b57cec5SDimitry Andric constexpr const T1& get(const pair<T1, T2>&) noexcept; // C++14 1330b57cec5SDimitry Andric 1340b57cec5SDimitry Andrictemplate<class T1, class T2> 1350b57cec5SDimitry Andric constexpr T1&& get(pair<T1, T2>&&) noexcept; // C++14 1360b57cec5SDimitry Andric 1370b57cec5SDimitry Andrictemplate<class T1, class T2> 1380b57cec5SDimitry Andric constexpr const T1&& get(const pair<T1, T2>&&) noexcept; // C++14 1390b57cec5SDimitry Andric 1400b57cec5SDimitry Andrictemplate<class T1, class T2> 1410b57cec5SDimitry Andric constexpr T1& get(pair<T2, T1>&) noexcept; // C++14 1420b57cec5SDimitry Andric 1430b57cec5SDimitry Andrictemplate<class T1, class T2> 1440b57cec5SDimitry Andric constexpr const T1& get(const pair<T2, T1>&) noexcept; // C++14 1450b57cec5SDimitry Andric 1460b57cec5SDimitry Andrictemplate<class T1, class T2> 1470b57cec5SDimitry Andric constexpr T1&& get(pair<T2, T1>&&) noexcept; // C++14 1480b57cec5SDimitry Andric 1490b57cec5SDimitry Andrictemplate<class T1, class T2> 1500b57cec5SDimitry Andric constexpr const T1&& get(const pair<T2, T1>&&) noexcept; // C++14 1510b57cec5SDimitry Andric 1520b57cec5SDimitry Andric// C++14 1530b57cec5SDimitry Andric 1540b57cec5SDimitry Andrictemplate<class T, T... I> 1550b57cec5SDimitry Andricstruct integer_sequence 1560b57cec5SDimitry Andric{ 1570b57cec5SDimitry Andric typedef T value_type; 1580b57cec5SDimitry Andric 1590b57cec5SDimitry Andric static constexpr size_t size() noexcept; 1600b57cec5SDimitry Andric}; 1610b57cec5SDimitry Andric 1620b57cec5SDimitry Andrictemplate<size_t... I> 1630b57cec5SDimitry Andric using index_sequence = integer_sequence<size_t, I...>; 1640b57cec5SDimitry Andric 1650b57cec5SDimitry Andrictemplate<class T, T N> 1660b57cec5SDimitry Andric using make_integer_sequence = integer_sequence<T, 0, 1, ..., N-1>; 1670b57cec5SDimitry Andrictemplate<size_t N> 1680b57cec5SDimitry Andric using make_index_sequence = make_integer_sequence<size_t, N>; 1690b57cec5SDimitry Andric 1700b57cec5SDimitry Andrictemplate<class... T> 1710b57cec5SDimitry Andric using index_sequence_for = make_index_sequence<sizeof...(T)>; 1720b57cec5SDimitry Andric 1730b57cec5SDimitry Andrictemplate<class T, class U=T> 1740b57cec5SDimitry Andric T exchange(T& obj, U&& new_value); 1750b57cec5SDimitry Andric 1760b57cec5SDimitry Andric// 20.2.7, in-place construction // C++17 1770b57cec5SDimitry Andricstruct in_place_t { 1780b57cec5SDimitry Andric explicit in_place_t() = default; 1790b57cec5SDimitry Andric}; 1800b57cec5SDimitry Andricinline constexpr in_place_t in_place{}; 1810b57cec5SDimitry Andrictemplate <class T> 1820b57cec5SDimitry Andric struct in_place_type_t { 1830b57cec5SDimitry Andric explicit in_place_type_t() = default; 1840b57cec5SDimitry Andric }; 1850b57cec5SDimitry Andrictemplate <class T> 1860b57cec5SDimitry Andric inline constexpr in_place_type_t<T> in_place_type{}; 1870b57cec5SDimitry Andrictemplate <size_t I> 1880b57cec5SDimitry Andric struct in_place_index_t { 1890b57cec5SDimitry Andric explicit in_place_index_t() = default; 1900b57cec5SDimitry Andric }; 1910b57cec5SDimitry Andrictemplate <size_t I> 1920b57cec5SDimitry Andric inline constexpr in_place_index_t<I> in_place_index{}; 1930b57cec5SDimitry Andric 1940b57cec5SDimitry Andric} // std 1950b57cec5SDimitry Andric 1960b57cec5SDimitry Andric*/ 1970b57cec5SDimitry Andric 1980b57cec5SDimitry Andric#include <__config> 1990b57cec5SDimitry Andric#include <__tuple> 2000b57cec5SDimitry Andric#include <type_traits> 2010b57cec5SDimitry Andric#include <initializer_list> 2020b57cec5SDimitry Andric#include <cstddef> 2030b57cec5SDimitry Andric#include <cstring> 2040b57cec5SDimitry Andric#include <cstdint> 2050b57cec5SDimitry Andric#include <version> 2060b57cec5SDimitry Andric#include <__debug> 2070b57cec5SDimitry Andric 2080b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 2090b57cec5SDimitry Andric#pragma GCC system_header 2100b57cec5SDimitry Andric#endif 2110b57cec5SDimitry Andric 2120b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD 2130b57cec5SDimitry Andric 2140b57cec5SDimitry Andricnamespace rel_ops 2150b57cec5SDimitry Andric{ 2160b57cec5SDimitry Andric 2170b57cec5SDimitry Andrictemplate<class _Tp> 2180b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 2190b57cec5SDimitry Andricbool 2200b57cec5SDimitry Andricoperator!=(const _Tp& __x, const _Tp& __y) 2210b57cec5SDimitry Andric{ 2220b57cec5SDimitry Andric return !(__x == __y); 2230b57cec5SDimitry Andric} 2240b57cec5SDimitry Andric 2250b57cec5SDimitry Andrictemplate<class _Tp> 2260b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 2270b57cec5SDimitry Andricbool 2280b57cec5SDimitry Andricoperator> (const _Tp& __x, const _Tp& __y) 2290b57cec5SDimitry Andric{ 2300b57cec5SDimitry Andric return __y < __x; 2310b57cec5SDimitry Andric} 2320b57cec5SDimitry Andric 2330b57cec5SDimitry Andrictemplate<class _Tp> 2340b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 2350b57cec5SDimitry Andricbool 2360b57cec5SDimitry Andricoperator<=(const _Tp& __x, const _Tp& __y) 2370b57cec5SDimitry Andric{ 2380b57cec5SDimitry Andric return !(__y < __x); 2390b57cec5SDimitry Andric} 2400b57cec5SDimitry Andric 2410b57cec5SDimitry Andrictemplate<class _Tp> 2420b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 2430b57cec5SDimitry Andricbool 2440b57cec5SDimitry Andricoperator>=(const _Tp& __x, const _Tp& __y) 2450b57cec5SDimitry Andric{ 2460b57cec5SDimitry Andric return !(__x < __y); 2470b57cec5SDimitry Andric} 2480b57cec5SDimitry Andric 2490b57cec5SDimitry Andric} // rel_ops 2500b57cec5SDimitry Andric 251*e40139ffSDimitry Andric// swap_ranges is defined in <type_traits>` 2520b57cec5SDimitry Andric 253*e40139ffSDimitry Andric// swap is defined in <type_traits> 2540b57cec5SDimitry Andric 255*e40139ffSDimitry Andric// move_if_noexcept 2560b57cec5SDimitry Andric 2570b57cec5SDimitry Andrictemplate <class _Tp> 2580b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 2590b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 2600b57cec5SDimitry Andrictypename conditional 2610b57cec5SDimitry Andric< 2620b57cec5SDimitry Andric !is_nothrow_move_constructible<_Tp>::value && is_copy_constructible<_Tp>::value, 2630b57cec5SDimitry Andric const _Tp&, 2640b57cec5SDimitry Andric _Tp&& 2650b57cec5SDimitry Andric>::type 2660b57cec5SDimitry Andric#else // _LIBCPP_CXX03_LANG 2670b57cec5SDimitry Andricconst _Tp& 2680b57cec5SDimitry Andric#endif 2690b57cec5SDimitry Andricmove_if_noexcept(_Tp& __x) _NOEXCEPT 2700b57cec5SDimitry Andric{ 2710b57cec5SDimitry Andric return _VSTD::move(__x); 2720b57cec5SDimitry Andric} 2730b57cec5SDimitry Andric 2740b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 2750b57cec5SDimitry Andrictemplate <class _Tp> constexpr add_const_t<_Tp>& as_const(_Tp& __t) noexcept { return __t; } 2760b57cec5SDimitry Andrictemplate <class _Tp> void as_const(const _Tp&&) = delete; 2770b57cec5SDimitry Andric#endif 2780b57cec5SDimitry Andric 279*e40139ffSDimitry Andricstruct _LIBCPP_TEMPLATE_VIS piecewise_construct_t { explicit piecewise_construct_t() = default; }; 2800b57cec5SDimitry Andric#if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY) 2810b57cec5SDimitry Andricextern _LIBCPP_EXPORTED_FROM_ABI const piecewise_construct_t piecewise_construct;// = piecewise_construct_t(); 2820b57cec5SDimitry Andric#else 2830b57cec5SDimitry Andric/* _LIBCPP_INLINE_VAR */ constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t(); 2840b57cec5SDimitry Andric#endif 2850b57cec5SDimitry Andric 2860b57cec5SDimitry Andric#if defined(_LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR) 2870b57cec5SDimitry Andrictemplate <class, class> 2880b57cec5SDimitry Andricstruct __non_trivially_copyable_base { 2890b57cec5SDimitry Andric _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY 2900b57cec5SDimitry Andric __non_trivially_copyable_base() _NOEXCEPT {} 2910b57cec5SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 2920b57cec5SDimitry Andric __non_trivially_copyable_base(__non_trivially_copyable_base const&) _NOEXCEPT {} 2930b57cec5SDimitry Andric}; 2940b57cec5SDimitry Andric#endif 2950b57cec5SDimitry Andric 2960b57cec5SDimitry Andrictemplate <class _T1, class _T2> 2970b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS pair 2980b57cec5SDimitry Andric#if defined(_LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR) 2990b57cec5SDimitry Andric: private __non_trivially_copyable_base<_T1, _T2> 3000b57cec5SDimitry Andric#endif 3010b57cec5SDimitry Andric{ 3020b57cec5SDimitry Andric typedef _T1 first_type; 3030b57cec5SDimitry Andric typedef _T2 second_type; 3040b57cec5SDimitry Andric 3050b57cec5SDimitry Andric _T1 first; 3060b57cec5SDimitry Andric _T2 second; 3070b57cec5SDimitry Andric 3080b57cec5SDimitry Andric#if !defined(_LIBCPP_CXX03_LANG) 3090b57cec5SDimitry Andric pair(pair const&) = default; 3100b57cec5SDimitry Andric pair(pair&&) = default; 3110b57cec5SDimitry Andric#else 3120b57cec5SDimitry Andric // Use the implicitly declared copy constructor in C++03 3130b57cec5SDimitry Andric#endif 3140b57cec5SDimitry Andric 3150b57cec5SDimitry Andric#ifdef _LIBCPP_CXX03_LANG 3160b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3170b57cec5SDimitry Andric pair() : first(), second() {} 3180b57cec5SDimitry Andric 3190b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3200b57cec5SDimitry Andric pair(_T1 const& __t1, _T2 const& __t2) : first(__t1), second(__t2) {} 3210b57cec5SDimitry Andric 3220b57cec5SDimitry Andric template <class _U1, class _U2> 3230b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3240b57cec5SDimitry Andric pair(const pair<_U1, _U2>& __p) : first(__p.first), second(__p.second) {} 3250b57cec5SDimitry Andric 3260b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3270b57cec5SDimitry Andric pair& operator=(pair const& __p) { 3280b57cec5SDimitry Andric first = __p.first; 3290b57cec5SDimitry Andric second = __p.second; 3300b57cec5SDimitry Andric return *this; 3310b57cec5SDimitry Andric } 3320b57cec5SDimitry Andric#else 3330b57cec5SDimitry Andric template <bool _Val> 3340b57cec5SDimitry Andric using _EnableB _LIBCPP_NODEBUG_TYPE = typename enable_if<_Val, bool>::type; 3350b57cec5SDimitry Andric 3360b57cec5SDimitry Andric struct _CheckArgs { 337*e40139ffSDimitry Andric template <int&...> 338*e40139ffSDimitry Andric static constexpr bool __enable_explicit_default() { 339*e40139ffSDimitry Andric return is_default_constructible<_T1>::value 340*e40139ffSDimitry Andric && is_default_constructible<_T2>::value 341*e40139ffSDimitry Andric && !__enable_implicit_default<>(); 342*e40139ffSDimitry Andric } 343*e40139ffSDimitry Andric 344*e40139ffSDimitry Andric template <int&...> 345*e40139ffSDimitry Andric static constexpr bool __enable_implicit_default() { 346*e40139ffSDimitry Andric return __is_implicitly_default_constructible<_T1>::value 347*e40139ffSDimitry Andric && __is_implicitly_default_constructible<_T2>::value; 3480b57cec5SDimitry Andric } 3490b57cec5SDimitry Andric 3500b57cec5SDimitry Andric template <class _U1, class _U2> 3510b57cec5SDimitry Andric static constexpr bool __enable_explicit() { 3520b57cec5SDimitry Andric return is_constructible<first_type, _U1>::value 3530b57cec5SDimitry Andric && is_constructible<second_type, _U2>::value 3540b57cec5SDimitry Andric && (!is_convertible<_U1, first_type>::value 3550b57cec5SDimitry Andric || !is_convertible<_U2, second_type>::value); 3560b57cec5SDimitry Andric } 3570b57cec5SDimitry Andric 3580b57cec5SDimitry Andric template <class _U1, class _U2> 3590b57cec5SDimitry Andric static constexpr bool __enable_implicit() { 3600b57cec5SDimitry Andric return is_constructible<first_type, _U1>::value 3610b57cec5SDimitry Andric && is_constructible<second_type, _U2>::value 3620b57cec5SDimitry Andric && is_convertible<_U1, first_type>::value 3630b57cec5SDimitry Andric && is_convertible<_U2, second_type>::value; 3640b57cec5SDimitry Andric } 3650b57cec5SDimitry Andric }; 3660b57cec5SDimitry Andric 3670b57cec5SDimitry Andric template <bool _MaybeEnable> 3680b57cec5SDimitry Andric using _CheckArgsDep _LIBCPP_NODEBUG_TYPE = typename conditional< 3690b57cec5SDimitry Andric _MaybeEnable, _CheckArgs, __check_tuple_constructor_fail>::type; 3700b57cec5SDimitry Andric 3710b57cec5SDimitry Andric struct _CheckTupleLikeConstructor { 3720b57cec5SDimitry Andric template <class _Tuple> 3730b57cec5SDimitry Andric static constexpr bool __enable_implicit() { 3740b57cec5SDimitry Andric return __tuple_convertible<_Tuple, pair>::value; 3750b57cec5SDimitry Andric } 3760b57cec5SDimitry Andric 3770b57cec5SDimitry Andric template <class _Tuple> 3780b57cec5SDimitry Andric static constexpr bool __enable_explicit() { 3790b57cec5SDimitry Andric return __tuple_constructible<_Tuple, pair>::value 3800b57cec5SDimitry Andric && !__tuple_convertible<_Tuple, pair>::value; 3810b57cec5SDimitry Andric } 3820b57cec5SDimitry Andric 3830b57cec5SDimitry Andric template <class _Tuple> 3840b57cec5SDimitry Andric static constexpr bool __enable_assign() { 3850b57cec5SDimitry Andric return __tuple_assignable<_Tuple, pair>::value; 3860b57cec5SDimitry Andric } 3870b57cec5SDimitry Andric }; 3880b57cec5SDimitry Andric 3890b57cec5SDimitry Andric template <class _Tuple> 3900b57cec5SDimitry Andric using _CheckTLC _LIBCPP_NODEBUG_TYPE = typename conditional< 3910b57cec5SDimitry Andric __tuple_like_with_size<_Tuple, 2>::value 3920b57cec5SDimitry Andric && !is_same<typename decay<_Tuple>::type, pair>::value, 3930b57cec5SDimitry Andric _CheckTupleLikeConstructor, 3940b57cec5SDimitry Andric __check_tuple_constructor_fail 3950b57cec5SDimitry Andric >::type; 3960b57cec5SDimitry Andric 3970b57cec5SDimitry Andric template<bool _Dummy = true, _EnableB< 398*e40139ffSDimitry Andric _CheckArgsDep<_Dummy>::__enable_explicit_default() 399*e40139ffSDimitry Andric > = false> 400*e40139ffSDimitry Andric explicit _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 401*e40139ffSDimitry Andric pair() _NOEXCEPT_(is_nothrow_default_constructible<first_type>::value && 402*e40139ffSDimitry Andric is_nothrow_default_constructible<second_type>::value) 403*e40139ffSDimitry Andric : first(), second() {} 404*e40139ffSDimitry Andric 405*e40139ffSDimitry Andric template<bool _Dummy = true, _EnableB< 406*e40139ffSDimitry Andric _CheckArgsDep<_Dummy>::__enable_implicit_default() 4070b57cec5SDimitry Andric > = false> 4080b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 4090b57cec5SDimitry Andric pair() _NOEXCEPT_(is_nothrow_default_constructible<first_type>::value && 4100b57cec5SDimitry Andric is_nothrow_default_constructible<second_type>::value) 4110b57cec5SDimitry Andric : first(), second() {} 4120b57cec5SDimitry Andric 4130b57cec5SDimitry Andric template <bool _Dummy = true, _EnableB< 4140b57cec5SDimitry Andric _CheckArgsDep<_Dummy>::template __enable_explicit<_T1 const&, _T2 const&>() 4150b57cec5SDimitry Andric > = false> 4160b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 4170b57cec5SDimitry Andric explicit pair(_T1 const& __t1, _T2 const& __t2) 4180b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_copy_constructible<first_type>::value && 4190b57cec5SDimitry Andric is_nothrow_copy_constructible<second_type>::value) 4200b57cec5SDimitry Andric : first(__t1), second(__t2) {} 4210b57cec5SDimitry Andric 4220b57cec5SDimitry Andric template<bool _Dummy = true, _EnableB< 4230b57cec5SDimitry Andric _CheckArgsDep<_Dummy>::template __enable_implicit<_T1 const&, _T2 const&>() 4240b57cec5SDimitry Andric > = false> 4250b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 4260b57cec5SDimitry Andric pair(_T1 const& __t1, _T2 const& __t2) 4270b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_copy_constructible<first_type>::value && 4280b57cec5SDimitry Andric is_nothrow_copy_constructible<second_type>::value) 4290b57cec5SDimitry Andric : first(__t1), second(__t2) {} 4300b57cec5SDimitry Andric 4310b57cec5SDimitry Andric template<class _U1, class _U2, _EnableB< 4320b57cec5SDimitry Andric _CheckArgs::template __enable_explicit<_U1, _U2>() 4330b57cec5SDimitry Andric > = false> 4340b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 4350b57cec5SDimitry Andric explicit pair(_U1&& __u1, _U2&& __u2) 4360b57cec5SDimitry Andric _NOEXCEPT_((is_nothrow_constructible<first_type, _U1>::value && 4370b57cec5SDimitry Andric is_nothrow_constructible<second_type, _U2>::value)) 4380b57cec5SDimitry Andric : first(_VSTD::forward<_U1>(__u1)), second(_VSTD::forward<_U2>(__u2)) {} 4390b57cec5SDimitry Andric 4400b57cec5SDimitry Andric template<class _U1, class _U2, _EnableB< 4410b57cec5SDimitry Andric _CheckArgs::template __enable_implicit<_U1, _U2>() 4420b57cec5SDimitry Andric > = false> 4430b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 4440b57cec5SDimitry Andric pair(_U1&& __u1, _U2&& __u2) 4450b57cec5SDimitry Andric _NOEXCEPT_((is_nothrow_constructible<first_type, _U1>::value && 4460b57cec5SDimitry Andric is_nothrow_constructible<second_type, _U2>::value)) 4470b57cec5SDimitry Andric : first(_VSTD::forward<_U1>(__u1)), second(_VSTD::forward<_U2>(__u2)) {} 4480b57cec5SDimitry Andric 4490b57cec5SDimitry Andric template<class _U1, class _U2, _EnableB< 4500b57cec5SDimitry Andric _CheckArgs::template __enable_explicit<_U1 const&, _U2 const&>() 4510b57cec5SDimitry Andric > = false> 4520b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 4530b57cec5SDimitry Andric explicit pair(pair<_U1, _U2> const& __p) 4540b57cec5SDimitry Andric _NOEXCEPT_((is_nothrow_constructible<first_type, _U1 const&>::value && 4550b57cec5SDimitry Andric is_nothrow_constructible<second_type, _U2 const&>::value)) 4560b57cec5SDimitry Andric : first(__p.first), second(__p.second) {} 4570b57cec5SDimitry Andric 4580b57cec5SDimitry Andric template<class _U1, class _U2, _EnableB< 4590b57cec5SDimitry Andric _CheckArgs::template __enable_implicit<_U1 const&, _U2 const&>() 4600b57cec5SDimitry Andric > = false> 4610b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 4620b57cec5SDimitry Andric pair(pair<_U1, _U2> const& __p) 4630b57cec5SDimitry Andric _NOEXCEPT_((is_nothrow_constructible<first_type, _U1 const&>::value && 4640b57cec5SDimitry Andric is_nothrow_constructible<second_type, _U2 const&>::value)) 4650b57cec5SDimitry Andric : first(__p.first), second(__p.second) {} 4660b57cec5SDimitry Andric 4670b57cec5SDimitry Andric template<class _U1, class _U2, _EnableB< 4680b57cec5SDimitry Andric _CheckArgs::template __enable_explicit<_U1, _U2>() 4690b57cec5SDimitry Andric > = false> 4700b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 4710b57cec5SDimitry Andric explicit pair(pair<_U1, _U2>&&__p) 4720b57cec5SDimitry Andric _NOEXCEPT_((is_nothrow_constructible<first_type, _U1&&>::value && 4730b57cec5SDimitry Andric is_nothrow_constructible<second_type, _U2&&>::value)) 4740b57cec5SDimitry Andric : first(_VSTD::forward<_U1>(__p.first)), second(_VSTD::forward<_U2>(__p.second)) {} 4750b57cec5SDimitry Andric 4760b57cec5SDimitry Andric template<class _U1, class _U2, _EnableB< 4770b57cec5SDimitry Andric _CheckArgs::template __enable_implicit<_U1, _U2>() 4780b57cec5SDimitry Andric > = false> 4790b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 4800b57cec5SDimitry Andric pair(pair<_U1, _U2>&& __p) 4810b57cec5SDimitry Andric _NOEXCEPT_((is_nothrow_constructible<first_type, _U1&&>::value && 4820b57cec5SDimitry Andric is_nothrow_constructible<second_type, _U2&&>::value)) 4830b57cec5SDimitry Andric : first(_VSTD::forward<_U1>(__p.first)), second(_VSTD::forward<_U2>(__p.second)) {} 4840b57cec5SDimitry Andric 4850b57cec5SDimitry Andric template<class _Tuple, _EnableB< 4860b57cec5SDimitry Andric _CheckTLC<_Tuple>::template __enable_explicit<_Tuple>() 4870b57cec5SDimitry Andric > = false> 4880b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 4890b57cec5SDimitry Andric explicit pair(_Tuple&& __p) 4900b57cec5SDimitry Andric : first(_VSTD::get<0>(_VSTD::forward<_Tuple>(__p))), 4910b57cec5SDimitry Andric second(_VSTD::get<1>(_VSTD::forward<_Tuple>(__p))) {} 4920b57cec5SDimitry Andric 4930b57cec5SDimitry Andric template<class _Tuple, _EnableB< 4940b57cec5SDimitry Andric _CheckTLC<_Tuple>::template __enable_implicit<_Tuple>() 4950b57cec5SDimitry Andric > = false> 4960b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 4970b57cec5SDimitry Andric pair(_Tuple&& __p) 4980b57cec5SDimitry Andric : first(_VSTD::get<0>(_VSTD::forward<_Tuple>(__p))), 4990b57cec5SDimitry Andric second(_VSTD::get<1>(_VSTD::forward<_Tuple>(__p))) {} 5000b57cec5SDimitry Andric 5010b57cec5SDimitry Andric template <class... _Args1, class... _Args2> 5020b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5030b57cec5SDimitry Andric pair(piecewise_construct_t __pc, 5040b57cec5SDimitry Andric tuple<_Args1...> __first_args, tuple<_Args2...> __second_args) 5050b57cec5SDimitry Andric _NOEXCEPT_((is_nothrow_constructible<first_type, _Args1...>::value && 5060b57cec5SDimitry Andric is_nothrow_constructible<second_type, _Args2...>::value)) 5070b57cec5SDimitry Andric : pair(__pc, __first_args, __second_args, 5080b57cec5SDimitry Andric typename __make_tuple_indices<sizeof...(_Args1)>::type(), 5090b57cec5SDimitry Andric typename __make_tuple_indices<sizeof...(_Args2) >::type()) {} 5100b57cec5SDimitry Andric 5110b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5120b57cec5SDimitry Andric pair& operator=(typename conditional< 5130b57cec5SDimitry Andric is_copy_assignable<first_type>::value && 5140b57cec5SDimitry Andric is_copy_assignable<second_type>::value, 5150b57cec5SDimitry Andric pair, __nat>::type const& __p) 5160b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_copy_assignable<first_type>::value && 5170b57cec5SDimitry Andric is_nothrow_copy_assignable<second_type>::value) 5180b57cec5SDimitry Andric { 5190b57cec5SDimitry Andric first = __p.first; 5200b57cec5SDimitry Andric second = __p.second; 5210b57cec5SDimitry Andric return *this; 5220b57cec5SDimitry Andric } 5230b57cec5SDimitry Andric 5240b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5250b57cec5SDimitry Andric pair& operator=(typename conditional< 5260b57cec5SDimitry Andric is_move_assignable<first_type>::value && 5270b57cec5SDimitry Andric is_move_assignable<second_type>::value, 5280b57cec5SDimitry Andric pair, __nat>::type&& __p) 5290b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_assignable<first_type>::value && 5300b57cec5SDimitry Andric is_nothrow_move_assignable<second_type>::value) 5310b57cec5SDimitry Andric { 5320b57cec5SDimitry Andric first = _VSTD::forward<first_type>(__p.first); 5330b57cec5SDimitry Andric second = _VSTD::forward<second_type>(__p.second); 5340b57cec5SDimitry Andric return *this; 5350b57cec5SDimitry Andric } 5360b57cec5SDimitry Andric 5370b57cec5SDimitry Andric template <class _Tuple, _EnableB< 5380b57cec5SDimitry Andric _CheckTLC<_Tuple>::template __enable_assign<_Tuple>() 5390b57cec5SDimitry Andric > = false> 5400b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5410b57cec5SDimitry Andric pair& operator=(_Tuple&& __p) { 5420b57cec5SDimitry Andric first = _VSTD::get<0>(_VSTD::forward<_Tuple>(__p)); 5430b57cec5SDimitry Andric second = _VSTD::get<1>(_VSTD::forward<_Tuple>(__p)); 5440b57cec5SDimitry Andric return *this; 5450b57cec5SDimitry Andric } 5460b57cec5SDimitry Andric#endif 5470b57cec5SDimitry Andric 5480b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5490b57cec5SDimitry Andric void 5500b57cec5SDimitry Andric swap(pair& __p) _NOEXCEPT_(__is_nothrow_swappable<first_type>::value && 5510b57cec5SDimitry Andric __is_nothrow_swappable<second_type>::value) 5520b57cec5SDimitry Andric { 5530b57cec5SDimitry Andric using _VSTD::swap; 5540b57cec5SDimitry Andric swap(first, __p.first); 5550b57cec5SDimitry Andric swap(second, __p.second); 5560b57cec5SDimitry Andric } 5570b57cec5SDimitry Andricprivate: 5580b57cec5SDimitry Andric 5590b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 5600b57cec5SDimitry Andric template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2> 5610b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5620b57cec5SDimitry Andric pair(piecewise_construct_t, 5630b57cec5SDimitry Andric tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args, 5640b57cec5SDimitry Andric __tuple_indices<_I1...>, __tuple_indices<_I2...>); 5650b57cec5SDimitry Andric#endif 5660b57cec5SDimitry Andric}; 5670b57cec5SDimitry Andric 5680b57cec5SDimitry Andric#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES 5690b57cec5SDimitry Andrictemplate<class _T1, class _T2> 5700b57cec5SDimitry Andricpair(_T1, _T2) -> pair<_T1, _T2>; 5710b57cec5SDimitry Andric#endif // _LIBCPP_HAS_NO_DEDUCTION_GUIDES 5720b57cec5SDimitry Andric 5730b57cec5SDimitry Andrictemplate <class _T1, class _T2> 5740b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 5750b57cec5SDimitry Andricbool 5760b57cec5SDimitry Andricoperator==(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) 5770b57cec5SDimitry Andric{ 5780b57cec5SDimitry Andric return __x.first == __y.first && __x.second == __y.second; 5790b57cec5SDimitry Andric} 5800b57cec5SDimitry Andric 5810b57cec5SDimitry Andrictemplate <class _T1, class _T2> 5820b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 5830b57cec5SDimitry Andricbool 5840b57cec5SDimitry Andricoperator!=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) 5850b57cec5SDimitry Andric{ 5860b57cec5SDimitry Andric return !(__x == __y); 5870b57cec5SDimitry Andric} 5880b57cec5SDimitry Andric 5890b57cec5SDimitry Andrictemplate <class _T1, class _T2> 5900b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 5910b57cec5SDimitry Andricbool 5920b57cec5SDimitry Andricoperator< (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) 5930b57cec5SDimitry Andric{ 5940b57cec5SDimitry Andric return __x.first < __y.first || (!(__y.first < __x.first) && __x.second < __y.second); 5950b57cec5SDimitry Andric} 5960b57cec5SDimitry Andric 5970b57cec5SDimitry Andrictemplate <class _T1, class _T2> 5980b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 5990b57cec5SDimitry Andricbool 6000b57cec5SDimitry Andricoperator> (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) 6010b57cec5SDimitry Andric{ 6020b57cec5SDimitry Andric return __y < __x; 6030b57cec5SDimitry Andric} 6040b57cec5SDimitry Andric 6050b57cec5SDimitry Andrictemplate <class _T1, class _T2> 6060b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 6070b57cec5SDimitry Andricbool 6080b57cec5SDimitry Andricoperator>=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) 6090b57cec5SDimitry Andric{ 6100b57cec5SDimitry Andric return !(__x < __y); 6110b57cec5SDimitry Andric} 6120b57cec5SDimitry Andric 6130b57cec5SDimitry Andrictemplate <class _T1, class _T2> 6140b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 6150b57cec5SDimitry Andricbool 6160b57cec5SDimitry Andricoperator<=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y) 6170b57cec5SDimitry Andric{ 6180b57cec5SDimitry Andric return !(__y < __x); 6190b57cec5SDimitry Andric} 6200b57cec5SDimitry Andric 6210b57cec5SDimitry Andrictemplate <class _T1, class _T2> 6220b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 6230b57cec5SDimitry Andrictypename enable_if 6240b57cec5SDimitry Andric< 6250b57cec5SDimitry Andric __is_swappable<_T1>::value && 6260b57cec5SDimitry Andric __is_swappable<_T2>::value, 6270b57cec5SDimitry Andric void 6280b57cec5SDimitry Andric>::type 6290b57cec5SDimitry Andricswap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y) 6300b57cec5SDimitry Andric _NOEXCEPT_((__is_nothrow_swappable<_T1>::value && 6310b57cec5SDimitry Andric __is_nothrow_swappable<_T2>::value)) 6320b57cec5SDimitry Andric{ 6330b57cec5SDimitry Andric __x.swap(__y); 6340b57cec5SDimitry Andric} 6350b57cec5SDimitry Andric 6360b57cec5SDimitry Andrictemplate <class _Tp> 6370b57cec5SDimitry Andricstruct __unwrap_reference { typedef _LIBCPP_NODEBUG_TYPE _Tp type; }; 6380b57cec5SDimitry Andric 6390b57cec5SDimitry Andrictemplate <class _Tp> 6400b57cec5SDimitry Andricstruct __unwrap_reference<reference_wrapper<_Tp> > { typedef _LIBCPP_NODEBUG_TYPE _Tp& type; }; 6410b57cec5SDimitry Andric 6420b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 17 6430b57cec5SDimitry Andrictemplate <class _Tp> 6440b57cec5SDimitry Andricstruct unwrap_reference : __unwrap_reference<_Tp> { }; 6450b57cec5SDimitry Andric 6460b57cec5SDimitry Andrictemplate <class _Tp> 6470b57cec5SDimitry Andricstruct unwrap_ref_decay : unwrap_reference<typename decay<_Tp>::type> { }; 6480b57cec5SDimitry Andric#endif // > C++17 6490b57cec5SDimitry Andric 6500b57cec5SDimitry Andrictemplate <class _Tp> 6510b57cec5SDimitry Andricstruct __unwrap_ref_decay 6520b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 17 6530b57cec5SDimitry Andric : unwrap_ref_decay<_Tp> 6540b57cec5SDimitry Andric#else 6550b57cec5SDimitry Andric : __unwrap_reference<typename decay<_Tp>::type> 6560b57cec5SDimitry Andric#endif 6570b57cec5SDimitry Andric{ }; 6580b57cec5SDimitry Andric 6590b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 6600b57cec5SDimitry Andric 6610b57cec5SDimitry Andrictemplate <class _T1, class _T2> 6620b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 6630b57cec5SDimitry Andricpair<typename __unwrap_ref_decay<_T1>::type, typename __unwrap_ref_decay<_T2>::type> 6640b57cec5SDimitry Andricmake_pair(_T1&& __t1, _T2&& __t2) 6650b57cec5SDimitry Andric{ 6660b57cec5SDimitry Andric return pair<typename __unwrap_ref_decay<_T1>::type, typename __unwrap_ref_decay<_T2>::type> 6670b57cec5SDimitry Andric (_VSTD::forward<_T1>(__t1), _VSTD::forward<_T2>(__t2)); 6680b57cec5SDimitry Andric} 6690b57cec5SDimitry Andric 6700b57cec5SDimitry Andric#else // _LIBCPP_CXX03_LANG 6710b57cec5SDimitry Andric 6720b57cec5SDimitry Andrictemplate <class _T1, class _T2> 6730b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 6740b57cec5SDimitry Andricpair<_T1,_T2> 6750b57cec5SDimitry Andricmake_pair(_T1 __x, _T2 __y) 6760b57cec5SDimitry Andric{ 6770b57cec5SDimitry Andric return pair<_T1, _T2>(__x, __y); 6780b57cec5SDimitry Andric} 6790b57cec5SDimitry Andric 6800b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 6810b57cec5SDimitry Andric 6820b57cec5SDimitry Andrictemplate <class _T1, class _T2> 6830b57cec5SDimitry Andric struct _LIBCPP_TEMPLATE_VIS tuple_size<pair<_T1, _T2> > 6840b57cec5SDimitry Andric : public integral_constant<size_t, 2> {}; 6850b57cec5SDimitry Andric 6860b57cec5SDimitry Andrictemplate <size_t _Ip, class _T1, class _T2> 6870b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, pair<_T1, _T2> > 6880b57cec5SDimitry Andric{ 6890b57cec5SDimitry Andric static_assert(_Ip < 2, "Index out of bounds in std::tuple_element<std::pair<T1, T2>>"); 6900b57cec5SDimitry Andric}; 6910b57cec5SDimitry Andric 6920b57cec5SDimitry Andrictemplate <class _T1, class _T2> 6930b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS tuple_element<0, pair<_T1, _T2> > 6940b57cec5SDimitry Andric{ 6950b57cec5SDimitry Andric typedef _LIBCPP_NODEBUG_TYPE _T1 type; 6960b57cec5SDimitry Andric}; 6970b57cec5SDimitry Andric 6980b57cec5SDimitry Andrictemplate <class _T1, class _T2> 6990b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS tuple_element<1, pair<_T1, _T2> > 7000b57cec5SDimitry Andric{ 7010b57cec5SDimitry Andric typedef _LIBCPP_NODEBUG_TYPE _T2 type; 7020b57cec5SDimitry Andric}; 7030b57cec5SDimitry Andric 7040b57cec5SDimitry Andrictemplate <size_t _Ip> struct __get_pair; 7050b57cec5SDimitry Andric 7060b57cec5SDimitry Andrictemplate <> 7070b57cec5SDimitry Andricstruct __get_pair<0> 7080b57cec5SDimitry Andric{ 7090b57cec5SDimitry Andric template <class _T1, class _T2> 7100b57cec5SDimitry Andric static 7110b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 7120b57cec5SDimitry Andric _T1& 7130b57cec5SDimitry Andric get(pair<_T1, _T2>& __p) _NOEXCEPT {return __p.first;} 7140b57cec5SDimitry Andric 7150b57cec5SDimitry Andric template <class _T1, class _T2> 7160b57cec5SDimitry Andric static 7170b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 7180b57cec5SDimitry Andric const _T1& 7190b57cec5SDimitry Andric get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.first;} 7200b57cec5SDimitry Andric 7210b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 7220b57cec5SDimitry Andric template <class _T1, class _T2> 7230b57cec5SDimitry Andric static 7240b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 7250b57cec5SDimitry Andric _T1&& 7260b57cec5SDimitry Andric get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<_T1>(__p.first);} 7270b57cec5SDimitry Andric 7280b57cec5SDimitry Andric template <class _T1, class _T2> 7290b57cec5SDimitry Andric static 7300b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 7310b57cec5SDimitry Andric const _T1&& 7320b57cec5SDimitry Andric get(const pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<const _T1>(__p.first);} 7330b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 7340b57cec5SDimitry Andric}; 7350b57cec5SDimitry Andric 7360b57cec5SDimitry Andrictemplate <> 7370b57cec5SDimitry Andricstruct __get_pair<1> 7380b57cec5SDimitry Andric{ 7390b57cec5SDimitry Andric template <class _T1, class _T2> 7400b57cec5SDimitry Andric static 7410b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 7420b57cec5SDimitry Andric _T2& 7430b57cec5SDimitry Andric get(pair<_T1, _T2>& __p) _NOEXCEPT {return __p.second;} 7440b57cec5SDimitry Andric 7450b57cec5SDimitry Andric template <class _T1, class _T2> 7460b57cec5SDimitry Andric static 7470b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 7480b57cec5SDimitry Andric const _T2& 7490b57cec5SDimitry Andric get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.second;} 7500b57cec5SDimitry Andric 7510b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 7520b57cec5SDimitry Andric template <class _T1, class _T2> 7530b57cec5SDimitry Andric static 7540b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 7550b57cec5SDimitry Andric _T2&& 7560b57cec5SDimitry Andric get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<_T2>(__p.second);} 7570b57cec5SDimitry Andric 7580b57cec5SDimitry Andric template <class _T1, class _T2> 7590b57cec5SDimitry Andric static 7600b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 7610b57cec5SDimitry Andric const _T2&& 7620b57cec5SDimitry Andric get(const pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<const _T2>(__p.second);} 7630b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 7640b57cec5SDimitry Andric}; 7650b57cec5SDimitry Andric 7660b57cec5SDimitry Andrictemplate <size_t _Ip, class _T1, class _T2> 7670b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 7680b57cec5SDimitry Andrictypename tuple_element<_Ip, pair<_T1, _T2> >::type& 7690b57cec5SDimitry Andricget(pair<_T1, _T2>& __p) _NOEXCEPT 7700b57cec5SDimitry Andric{ 7710b57cec5SDimitry Andric return __get_pair<_Ip>::get(__p); 7720b57cec5SDimitry Andric} 7730b57cec5SDimitry Andric 7740b57cec5SDimitry Andrictemplate <size_t _Ip, class _T1, class _T2> 7750b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 7760b57cec5SDimitry Andricconst typename tuple_element<_Ip, pair<_T1, _T2> >::type& 7770b57cec5SDimitry Andricget(const pair<_T1, _T2>& __p) _NOEXCEPT 7780b57cec5SDimitry Andric{ 7790b57cec5SDimitry Andric return __get_pair<_Ip>::get(__p); 7800b57cec5SDimitry Andric} 7810b57cec5SDimitry Andric 7820b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 7830b57cec5SDimitry Andrictemplate <size_t _Ip, class _T1, class _T2> 7840b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 7850b57cec5SDimitry Andrictypename tuple_element<_Ip, pair<_T1, _T2> >::type&& 7860b57cec5SDimitry Andricget(pair<_T1, _T2>&& __p) _NOEXCEPT 7870b57cec5SDimitry Andric{ 7880b57cec5SDimitry Andric return __get_pair<_Ip>::get(_VSTD::move(__p)); 7890b57cec5SDimitry Andric} 7900b57cec5SDimitry Andric 7910b57cec5SDimitry Andrictemplate <size_t _Ip, class _T1, class _T2> 7920b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 7930b57cec5SDimitry Andricconst typename tuple_element<_Ip, pair<_T1, _T2> >::type&& 7940b57cec5SDimitry Andricget(const pair<_T1, _T2>&& __p) _NOEXCEPT 7950b57cec5SDimitry Andric{ 7960b57cec5SDimitry Andric return __get_pair<_Ip>::get(_VSTD::move(__p)); 7970b57cec5SDimitry Andric} 7980b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 7990b57cec5SDimitry Andric 8000b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 8010b57cec5SDimitry Andrictemplate <class _T1, class _T2> 8020b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 8030b57cec5SDimitry Andricconstexpr _T1 & get(pair<_T1, _T2>& __p) _NOEXCEPT 8040b57cec5SDimitry Andric{ 8050b57cec5SDimitry Andric return __get_pair<0>::get(__p); 8060b57cec5SDimitry Andric} 8070b57cec5SDimitry Andric 8080b57cec5SDimitry Andrictemplate <class _T1, class _T2> 8090b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 8100b57cec5SDimitry Andricconstexpr _T1 const & get(pair<_T1, _T2> const& __p) _NOEXCEPT 8110b57cec5SDimitry Andric{ 8120b57cec5SDimitry Andric return __get_pair<0>::get(__p); 8130b57cec5SDimitry Andric} 8140b57cec5SDimitry Andric 8150b57cec5SDimitry Andrictemplate <class _T1, class _T2> 8160b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 8170b57cec5SDimitry Andricconstexpr _T1 && get(pair<_T1, _T2>&& __p) _NOEXCEPT 8180b57cec5SDimitry Andric{ 8190b57cec5SDimitry Andric return __get_pair<0>::get(_VSTD::move(__p)); 8200b57cec5SDimitry Andric} 8210b57cec5SDimitry Andric 8220b57cec5SDimitry Andrictemplate <class _T1, class _T2> 8230b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 8240b57cec5SDimitry Andricconstexpr _T1 const && get(pair<_T1, _T2> const&& __p) _NOEXCEPT 8250b57cec5SDimitry Andric{ 8260b57cec5SDimitry Andric return __get_pair<0>::get(_VSTD::move(__p)); 8270b57cec5SDimitry Andric} 8280b57cec5SDimitry Andric 8290b57cec5SDimitry Andrictemplate <class _T1, class _T2> 8300b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 8310b57cec5SDimitry Andricconstexpr _T1 & get(pair<_T2, _T1>& __p) _NOEXCEPT 8320b57cec5SDimitry Andric{ 8330b57cec5SDimitry Andric return __get_pair<1>::get(__p); 8340b57cec5SDimitry Andric} 8350b57cec5SDimitry Andric 8360b57cec5SDimitry Andrictemplate <class _T1, class _T2> 8370b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 8380b57cec5SDimitry Andricconstexpr _T1 const & get(pair<_T2, _T1> const& __p) _NOEXCEPT 8390b57cec5SDimitry Andric{ 8400b57cec5SDimitry Andric return __get_pair<1>::get(__p); 8410b57cec5SDimitry Andric} 8420b57cec5SDimitry Andric 8430b57cec5SDimitry Andrictemplate <class _T1, class _T2> 8440b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 8450b57cec5SDimitry Andricconstexpr _T1 && get(pair<_T2, _T1>&& __p) _NOEXCEPT 8460b57cec5SDimitry Andric{ 8470b57cec5SDimitry Andric return __get_pair<1>::get(_VSTD::move(__p)); 8480b57cec5SDimitry Andric} 8490b57cec5SDimitry Andric 8500b57cec5SDimitry Andrictemplate <class _T1, class _T2> 8510b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 8520b57cec5SDimitry Andricconstexpr _T1 const && get(pair<_T2, _T1> const&& __p) _NOEXCEPT 8530b57cec5SDimitry Andric{ 8540b57cec5SDimitry Andric return __get_pair<1>::get(_VSTD::move(__p)); 8550b57cec5SDimitry Andric} 8560b57cec5SDimitry Andric 8570b57cec5SDimitry Andric#endif 8580b57cec5SDimitry Andric 8590b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 8600b57cec5SDimitry Andric 8610b57cec5SDimitry Andrictemplate<class _Tp, _Tp... _Ip> 8620b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS integer_sequence 8630b57cec5SDimitry Andric{ 8640b57cec5SDimitry Andric typedef _Tp value_type; 8650b57cec5SDimitry Andric static_assert( is_integral<_Tp>::value, 8660b57cec5SDimitry Andric "std::integer_sequence can only be instantiated with an integral type" ); 8670b57cec5SDimitry Andric static 8680b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 8690b57cec5SDimitry Andric constexpr 8700b57cec5SDimitry Andric size_t 8710b57cec5SDimitry Andric size() noexcept { return sizeof...(_Ip); } 8720b57cec5SDimitry Andric}; 8730b57cec5SDimitry Andric 8740b57cec5SDimitry Andrictemplate<size_t... _Ip> 8750b57cec5SDimitry Andric using index_sequence = integer_sequence<size_t, _Ip...>; 8760b57cec5SDimitry Andric 8770b57cec5SDimitry Andric#if __has_builtin(__make_integer_seq) && !defined(_LIBCPP_TESTING_FALLBACK_MAKE_INTEGER_SEQUENCE) 8780b57cec5SDimitry Andric 8790b57cec5SDimitry Andrictemplate <class _Tp, _Tp _Ep> 8800b57cec5SDimitry Andricusing __make_integer_sequence _LIBCPP_NODEBUG_TYPE = __make_integer_seq<integer_sequence, _Tp, _Ep>; 8810b57cec5SDimitry Andric 8820b57cec5SDimitry Andric#else 8830b57cec5SDimitry Andric 8840b57cec5SDimitry Andrictemplate<typename _Tp, _Tp _Np> using __make_integer_sequence_unchecked _LIBCPP_NODEBUG_TYPE = 8850b57cec5SDimitry Andric typename __detail::__make<_Np>::type::template __convert<integer_sequence, _Tp>; 8860b57cec5SDimitry Andric 8870b57cec5SDimitry Andrictemplate <class _Tp, _Tp _Ep> 8880b57cec5SDimitry Andricstruct __make_integer_sequence_checked 8890b57cec5SDimitry Andric{ 8900b57cec5SDimitry Andric static_assert(is_integral<_Tp>::value, 8910b57cec5SDimitry Andric "std::make_integer_sequence can only be instantiated with an integral type" ); 8920b57cec5SDimitry Andric static_assert(0 <= _Ep, "std::make_integer_sequence must have a non-negative sequence length"); 8930b57cec5SDimitry Andric // Workaround GCC bug by preventing bad installations when 0 <= _Ep 8940b57cec5SDimitry Andric // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68929 8950b57cec5SDimitry Andric typedef _LIBCPP_NODEBUG_TYPE __make_integer_sequence_unchecked<_Tp, 0 <= _Ep ? _Ep : 0> type; 8960b57cec5SDimitry Andric}; 8970b57cec5SDimitry Andric 8980b57cec5SDimitry Andrictemplate <class _Tp, _Tp _Ep> 8990b57cec5SDimitry Andricusing __make_integer_sequence _LIBCPP_NODEBUG_TYPE = typename __make_integer_sequence_checked<_Tp, _Ep>::type; 9000b57cec5SDimitry Andric 9010b57cec5SDimitry Andric#endif 9020b57cec5SDimitry Andric 9030b57cec5SDimitry Andrictemplate<class _Tp, _Tp _Np> 9040b57cec5SDimitry Andric using make_integer_sequence = __make_integer_sequence<_Tp, _Np>; 9050b57cec5SDimitry Andric 9060b57cec5SDimitry Andrictemplate<size_t _Np> 9070b57cec5SDimitry Andric using make_index_sequence = make_integer_sequence<size_t, _Np>; 9080b57cec5SDimitry Andric 9090b57cec5SDimitry Andrictemplate<class... _Tp> 9100b57cec5SDimitry Andric using index_sequence_for = make_index_sequence<sizeof...(_Tp)>; 9110b57cec5SDimitry Andric 9120b57cec5SDimitry Andric#endif // _LIBCPP_STD_VER > 11 9130b57cec5SDimitry Andric 9140b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 9150b57cec5SDimitry Andrictemplate<class _T1, class _T2 = _T1> 9160b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 9170b57cec5SDimitry Andric_T1 exchange(_T1& __obj, _T2 && __new_value) 9180b57cec5SDimitry Andric{ 9190b57cec5SDimitry Andric _T1 __old_value = _VSTD::move(__obj); 9200b57cec5SDimitry Andric __obj = _VSTD::forward<_T2>(__new_value); 9210b57cec5SDimitry Andric return __old_value; 9220b57cec5SDimitry Andric} 9230b57cec5SDimitry Andric#endif // _LIBCPP_STD_VER > 11 9240b57cec5SDimitry Andric 9250b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 9260b57cec5SDimitry Andric 9270b57cec5SDimitry Andricstruct _LIBCPP_TYPE_VIS in_place_t { 9280b57cec5SDimitry Andric explicit in_place_t() = default; 9290b57cec5SDimitry Andric}; 9300b57cec5SDimitry Andric_LIBCPP_INLINE_VAR constexpr in_place_t in_place{}; 9310b57cec5SDimitry Andric 9320b57cec5SDimitry Andrictemplate <class _Tp> 9330b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS in_place_type_t { 9340b57cec5SDimitry Andric explicit in_place_type_t() = default; 9350b57cec5SDimitry Andric}; 9360b57cec5SDimitry Andrictemplate <class _Tp> 9370b57cec5SDimitry Andric_LIBCPP_INLINE_VAR constexpr in_place_type_t<_Tp> in_place_type{}; 9380b57cec5SDimitry Andric 9390b57cec5SDimitry Andrictemplate <size_t _Idx> 9400b57cec5SDimitry Andricstruct _LIBCPP_TYPE_VIS in_place_index_t { 9410b57cec5SDimitry Andric explicit in_place_index_t() = default; 9420b57cec5SDimitry Andric}; 9430b57cec5SDimitry Andrictemplate <size_t _Idx> 9440b57cec5SDimitry Andric_LIBCPP_INLINE_VAR constexpr in_place_index_t<_Idx> in_place_index{}; 9450b57cec5SDimitry Andric 9460b57cec5SDimitry Andrictemplate <class _Tp> struct __is_inplace_type_imp : false_type {}; 9470b57cec5SDimitry Andrictemplate <class _Tp> struct __is_inplace_type_imp<in_place_type_t<_Tp>> : true_type {}; 9480b57cec5SDimitry Andric 9490b57cec5SDimitry Andrictemplate <class _Tp> 9500b57cec5SDimitry Andricusing __is_inplace_type = __is_inplace_type_imp<__uncvref_t<_Tp>>; 9510b57cec5SDimitry Andric 9520b57cec5SDimitry Andrictemplate <class _Tp> struct __is_inplace_index_imp : false_type {}; 9530b57cec5SDimitry Andrictemplate <size_t _Idx> struct __is_inplace_index_imp<in_place_index_t<_Idx>> : true_type {}; 9540b57cec5SDimitry Andric 9550b57cec5SDimitry Andrictemplate <class _Tp> 9560b57cec5SDimitry Andricusing __is_inplace_index = __is_inplace_index_imp<__uncvref_t<_Tp>>; 9570b57cec5SDimitry Andric 9580b57cec5SDimitry Andric#endif // _LIBCPP_STD_VER > 14 9590b57cec5SDimitry Andric 9600b57cec5SDimitry Andrictemplate <class _Arg, class _Result> 9610b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS unary_function 9620b57cec5SDimitry Andric{ 9630b57cec5SDimitry Andric typedef _Arg argument_type; 9640b57cec5SDimitry Andric typedef _Result result_type; 9650b57cec5SDimitry Andric}; 9660b57cec5SDimitry Andric 9670b57cec5SDimitry Andrictemplate <class _Size> 9680b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 9690b57cec5SDimitry Andric_Size 9700b57cec5SDimitry Andric__loadword(const void* __p) 9710b57cec5SDimitry Andric{ 9720b57cec5SDimitry Andric _Size __r; 9730b57cec5SDimitry Andric std::memcpy(&__r, __p, sizeof(__r)); 9740b57cec5SDimitry Andric return __r; 9750b57cec5SDimitry Andric} 9760b57cec5SDimitry Andric 9770b57cec5SDimitry Andric// We use murmur2 when size_t is 32 bits, and cityhash64 when size_t 9780b57cec5SDimitry Andric// is 64 bits. This is because cityhash64 uses 64bit x 64bit 9790b57cec5SDimitry Andric// multiplication, which can be very slow on 32-bit systems. 9800b57cec5SDimitry Andrictemplate <class _Size, size_t = sizeof(_Size)*__CHAR_BIT__> 9810b57cec5SDimitry Andricstruct __murmur2_or_cityhash; 9820b57cec5SDimitry Andric 9830b57cec5SDimitry Andrictemplate <class _Size> 9840b57cec5SDimitry Andricstruct __murmur2_or_cityhash<_Size, 32> 9850b57cec5SDimitry Andric{ 9860b57cec5SDimitry Andric inline _Size operator()(const void* __key, _Size __len) 9870b57cec5SDimitry Andric _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK; 9880b57cec5SDimitry Andric}; 9890b57cec5SDimitry Andric 9900b57cec5SDimitry Andric// murmur2 9910b57cec5SDimitry Andrictemplate <class _Size> 9920b57cec5SDimitry Andric_Size 9930b57cec5SDimitry Andric__murmur2_or_cityhash<_Size, 32>::operator()(const void* __key, _Size __len) 9940b57cec5SDimitry Andric{ 9950b57cec5SDimitry Andric const _Size __m = 0x5bd1e995; 9960b57cec5SDimitry Andric const _Size __r = 24; 9970b57cec5SDimitry Andric _Size __h = __len; 9980b57cec5SDimitry Andric const unsigned char* __data = static_cast<const unsigned char*>(__key); 9990b57cec5SDimitry Andric for (; __len >= 4; __data += 4, __len -= 4) 10000b57cec5SDimitry Andric { 10010b57cec5SDimitry Andric _Size __k = __loadword<_Size>(__data); 10020b57cec5SDimitry Andric __k *= __m; 10030b57cec5SDimitry Andric __k ^= __k >> __r; 10040b57cec5SDimitry Andric __k *= __m; 10050b57cec5SDimitry Andric __h *= __m; 10060b57cec5SDimitry Andric __h ^= __k; 10070b57cec5SDimitry Andric } 10080b57cec5SDimitry Andric switch (__len) 10090b57cec5SDimitry Andric { 10100b57cec5SDimitry Andric case 3: 10110b57cec5SDimitry Andric __h ^= __data[2] << 16; 10120b57cec5SDimitry Andric _LIBCPP_FALLTHROUGH(); 10130b57cec5SDimitry Andric case 2: 10140b57cec5SDimitry Andric __h ^= __data[1] << 8; 10150b57cec5SDimitry Andric _LIBCPP_FALLTHROUGH(); 10160b57cec5SDimitry Andric case 1: 10170b57cec5SDimitry Andric __h ^= __data[0]; 10180b57cec5SDimitry Andric __h *= __m; 10190b57cec5SDimitry Andric } 10200b57cec5SDimitry Andric __h ^= __h >> 13; 10210b57cec5SDimitry Andric __h *= __m; 10220b57cec5SDimitry Andric __h ^= __h >> 15; 10230b57cec5SDimitry Andric return __h; 10240b57cec5SDimitry Andric} 10250b57cec5SDimitry Andric 10260b57cec5SDimitry Andrictemplate <class _Size> 10270b57cec5SDimitry Andricstruct __murmur2_or_cityhash<_Size, 64> 10280b57cec5SDimitry Andric{ 10290b57cec5SDimitry Andric inline _Size operator()(const void* __key, _Size __len) _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK; 10300b57cec5SDimitry Andric 10310b57cec5SDimitry Andric private: 10320b57cec5SDimitry Andric // Some primes between 2^63 and 2^64. 10330b57cec5SDimitry Andric static const _Size __k0 = 0xc3a5c85c97cb3127ULL; 10340b57cec5SDimitry Andric static const _Size __k1 = 0xb492b66fbe98f273ULL; 10350b57cec5SDimitry Andric static const _Size __k2 = 0x9ae16a3b2f90404fULL; 10360b57cec5SDimitry Andric static const _Size __k3 = 0xc949d7c7509e6557ULL; 10370b57cec5SDimitry Andric 10380b57cec5SDimitry Andric static _Size __rotate(_Size __val, int __shift) { 10390b57cec5SDimitry Andric return __shift == 0 ? __val : ((__val >> __shift) | (__val << (64 - __shift))); 10400b57cec5SDimitry Andric } 10410b57cec5SDimitry Andric 10420b57cec5SDimitry Andric static _Size __rotate_by_at_least_1(_Size __val, int __shift) { 10430b57cec5SDimitry Andric return (__val >> __shift) | (__val << (64 - __shift)); 10440b57cec5SDimitry Andric } 10450b57cec5SDimitry Andric 10460b57cec5SDimitry Andric static _Size __shift_mix(_Size __val) { 10470b57cec5SDimitry Andric return __val ^ (__val >> 47); 10480b57cec5SDimitry Andric } 10490b57cec5SDimitry Andric 10500b57cec5SDimitry Andric static _Size __hash_len_16(_Size __u, _Size __v) 10510b57cec5SDimitry Andric _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK 10520b57cec5SDimitry Andric { 10530b57cec5SDimitry Andric const _Size __mul = 0x9ddfea08eb382d69ULL; 10540b57cec5SDimitry Andric _Size __a = (__u ^ __v) * __mul; 10550b57cec5SDimitry Andric __a ^= (__a >> 47); 10560b57cec5SDimitry Andric _Size __b = (__v ^ __a) * __mul; 10570b57cec5SDimitry Andric __b ^= (__b >> 47); 10580b57cec5SDimitry Andric __b *= __mul; 10590b57cec5SDimitry Andric return __b; 10600b57cec5SDimitry Andric } 10610b57cec5SDimitry Andric 10620b57cec5SDimitry Andric static _Size __hash_len_0_to_16(const char* __s, _Size __len) 10630b57cec5SDimitry Andric _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK 10640b57cec5SDimitry Andric { 10650b57cec5SDimitry Andric if (__len > 8) { 10660b57cec5SDimitry Andric const _Size __a = __loadword<_Size>(__s); 10670b57cec5SDimitry Andric const _Size __b = __loadword<_Size>(__s + __len - 8); 10680b57cec5SDimitry Andric return __hash_len_16(__a, __rotate_by_at_least_1(__b + __len, __len)) ^ __b; 10690b57cec5SDimitry Andric } 10700b57cec5SDimitry Andric if (__len >= 4) { 10710b57cec5SDimitry Andric const uint32_t __a = __loadword<uint32_t>(__s); 10720b57cec5SDimitry Andric const uint32_t __b = __loadword<uint32_t>(__s + __len - 4); 10730b57cec5SDimitry Andric return __hash_len_16(__len + (__a << 3), __b); 10740b57cec5SDimitry Andric } 10750b57cec5SDimitry Andric if (__len > 0) { 10760b57cec5SDimitry Andric const unsigned char __a = __s[0]; 10770b57cec5SDimitry Andric const unsigned char __b = __s[__len >> 1]; 10780b57cec5SDimitry Andric const unsigned char __c = __s[__len - 1]; 10790b57cec5SDimitry Andric const uint32_t __y = static_cast<uint32_t>(__a) + 10800b57cec5SDimitry Andric (static_cast<uint32_t>(__b) << 8); 10810b57cec5SDimitry Andric const uint32_t __z = __len + (static_cast<uint32_t>(__c) << 2); 10820b57cec5SDimitry Andric return __shift_mix(__y * __k2 ^ __z * __k3) * __k2; 10830b57cec5SDimitry Andric } 10840b57cec5SDimitry Andric return __k2; 10850b57cec5SDimitry Andric } 10860b57cec5SDimitry Andric 10870b57cec5SDimitry Andric static _Size __hash_len_17_to_32(const char *__s, _Size __len) 10880b57cec5SDimitry Andric _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK 10890b57cec5SDimitry Andric { 10900b57cec5SDimitry Andric const _Size __a = __loadword<_Size>(__s) * __k1; 10910b57cec5SDimitry Andric const _Size __b = __loadword<_Size>(__s + 8); 10920b57cec5SDimitry Andric const _Size __c = __loadword<_Size>(__s + __len - 8) * __k2; 10930b57cec5SDimitry Andric const _Size __d = __loadword<_Size>(__s + __len - 16) * __k0; 10940b57cec5SDimitry Andric return __hash_len_16(__rotate(__a - __b, 43) + __rotate(__c, 30) + __d, 10950b57cec5SDimitry Andric __a + __rotate(__b ^ __k3, 20) - __c + __len); 10960b57cec5SDimitry Andric } 10970b57cec5SDimitry Andric 10980b57cec5SDimitry Andric // Return a 16-byte hash for 48 bytes. Quick and dirty. 10990b57cec5SDimitry Andric // Callers do best to use "random-looking" values for a and b. 11000b57cec5SDimitry Andric static pair<_Size, _Size> __weak_hash_len_32_with_seeds( 11010b57cec5SDimitry Andric _Size __w, _Size __x, _Size __y, _Size __z, _Size __a, _Size __b) 11020b57cec5SDimitry Andric _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK 11030b57cec5SDimitry Andric { 11040b57cec5SDimitry Andric __a += __w; 11050b57cec5SDimitry Andric __b = __rotate(__b + __a + __z, 21); 11060b57cec5SDimitry Andric const _Size __c = __a; 11070b57cec5SDimitry Andric __a += __x; 11080b57cec5SDimitry Andric __a += __y; 11090b57cec5SDimitry Andric __b += __rotate(__a, 44); 11100b57cec5SDimitry Andric return pair<_Size, _Size>(__a + __z, __b + __c); 11110b57cec5SDimitry Andric } 11120b57cec5SDimitry Andric 11130b57cec5SDimitry Andric // Return a 16-byte hash for s[0] ... s[31], a, and b. Quick and dirty. 11140b57cec5SDimitry Andric static pair<_Size, _Size> __weak_hash_len_32_with_seeds( 11150b57cec5SDimitry Andric const char* __s, _Size __a, _Size __b) 11160b57cec5SDimitry Andric _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK 11170b57cec5SDimitry Andric { 11180b57cec5SDimitry Andric return __weak_hash_len_32_with_seeds(__loadword<_Size>(__s), 11190b57cec5SDimitry Andric __loadword<_Size>(__s + 8), 11200b57cec5SDimitry Andric __loadword<_Size>(__s + 16), 11210b57cec5SDimitry Andric __loadword<_Size>(__s + 24), 11220b57cec5SDimitry Andric __a, 11230b57cec5SDimitry Andric __b); 11240b57cec5SDimitry Andric } 11250b57cec5SDimitry Andric 11260b57cec5SDimitry Andric // Return an 8-byte hash for 33 to 64 bytes. 11270b57cec5SDimitry Andric static _Size __hash_len_33_to_64(const char *__s, size_t __len) 11280b57cec5SDimitry Andric _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK 11290b57cec5SDimitry Andric { 11300b57cec5SDimitry Andric _Size __z = __loadword<_Size>(__s + 24); 11310b57cec5SDimitry Andric _Size __a = __loadword<_Size>(__s) + 11320b57cec5SDimitry Andric (__len + __loadword<_Size>(__s + __len - 16)) * __k0; 11330b57cec5SDimitry Andric _Size __b = __rotate(__a + __z, 52); 11340b57cec5SDimitry Andric _Size __c = __rotate(__a, 37); 11350b57cec5SDimitry Andric __a += __loadword<_Size>(__s + 8); 11360b57cec5SDimitry Andric __c += __rotate(__a, 7); 11370b57cec5SDimitry Andric __a += __loadword<_Size>(__s + 16); 11380b57cec5SDimitry Andric _Size __vf = __a + __z; 11390b57cec5SDimitry Andric _Size __vs = __b + __rotate(__a, 31) + __c; 11400b57cec5SDimitry Andric __a = __loadword<_Size>(__s + 16) + __loadword<_Size>(__s + __len - 32); 11410b57cec5SDimitry Andric __z += __loadword<_Size>(__s + __len - 8); 11420b57cec5SDimitry Andric __b = __rotate(__a + __z, 52); 11430b57cec5SDimitry Andric __c = __rotate(__a, 37); 11440b57cec5SDimitry Andric __a += __loadword<_Size>(__s + __len - 24); 11450b57cec5SDimitry Andric __c += __rotate(__a, 7); 11460b57cec5SDimitry Andric __a += __loadword<_Size>(__s + __len - 16); 11470b57cec5SDimitry Andric _Size __wf = __a + __z; 11480b57cec5SDimitry Andric _Size __ws = __b + __rotate(__a, 31) + __c; 11490b57cec5SDimitry Andric _Size __r = __shift_mix((__vf + __ws) * __k2 + (__wf + __vs) * __k0); 11500b57cec5SDimitry Andric return __shift_mix(__r * __k0 + __vs) * __k2; 11510b57cec5SDimitry Andric } 11520b57cec5SDimitry Andric}; 11530b57cec5SDimitry Andric 11540b57cec5SDimitry Andric// cityhash64 11550b57cec5SDimitry Andrictemplate <class _Size> 11560b57cec5SDimitry Andric_Size 11570b57cec5SDimitry Andric__murmur2_or_cityhash<_Size, 64>::operator()(const void* __key, _Size __len) 11580b57cec5SDimitry Andric{ 11590b57cec5SDimitry Andric const char* __s = static_cast<const char*>(__key); 11600b57cec5SDimitry Andric if (__len <= 32) { 11610b57cec5SDimitry Andric if (__len <= 16) { 11620b57cec5SDimitry Andric return __hash_len_0_to_16(__s, __len); 11630b57cec5SDimitry Andric } else { 11640b57cec5SDimitry Andric return __hash_len_17_to_32(__s, __len); 11650b57cec5SDimitry Andric } 11660b57cec5SDimitry Andric } else if (__len <= 64) { 11670b57cec5SDimitry Andric return __hash_len_33_to_64(__s, __len); 11680b57cec5SDimitry Andric } 11690b57cec5SDimitry Andric 11700b57cec5SDimitry Andric // For strings over 64 bytes we hash the end first, and then as we 11710b57cec5SDimitry Andric // loop we keep 56 bytes of state: v, w, x, y, and z. 11720b57cec5SDimitry Andric _Size __x = __loadword<_Size>(__s + __len - 40); 11730b57cec5SDimitry Andric _Size __y = __loadword<_Size>(__s + __len - 16) + 11740b57cec5SDimitry Andric __loadword<_Size>(__s + __len - 56); 11750b57cec5SDimitry Andric _Size __z = __hash_len_16(__loadword<_Size>(__s + __len - 48) + __len, 11760b57cec5SDimitry Andric __loadword<_Size>(__s + __len - 24)); 11770b57cec5SDimitry Andric pair<_Size, _Size> __v = __weak_hash_len_32_with_seeds(__s + __len - 64, __len, __z); 11780b57cec5SDimitry Andric pair<_Size, _Size> __w = __weak_hash_len_32_with_seeds(__s + __len - 32, __y + __k1, __x); 11790b57cec5SDimitry Andric __x = __x * __k1 + __loadword<_Size>(__s); 11800b57cec5SDimitry Andric 11810b57cec5SDimitry Andric // Decrease len to the nearest multiple of 64, and operate on 64-byte chunks. 11820b57cec5SDimitry Andric __len = (__len - 1) & ~static_cast<_Size>(63); 11830b57cec5SDimitry Andric do { 11840b57cec5SDimitry Andric __x = __rotate(__x + __y + __v.first + __loadword<_Size>(__s + 8), 37) * __k1; 11850b57cec5SDimitry Andric __y = __rotate(__y + __v.second + __loadword<_Size>(__s + 48), 42) * __k1; 11860b57cec5SDimitry Andric __x ^= __w.second; 11870b57cec5SDimitry Andric __y += __v.first + __loadword<_Size>(__s + 40); 11880b57cec5SDimitry Andric __z = __rotate(__z + __w.first, 33) * __k1; 11890b57cec5SDimitry Andric __v = __weak_hash_len_32_with_seeds(__s, __v.second * __k1, __x + __w.first); 11900b57cec5SDimitry Andric __w = __weak_hash_len_32_with_seeds(__s + 32, __z + __w.second, 11910b57cec5SDimitry Andric __y + __loadword<_Size>(__s + 16)); 11920b57cec5SDimitry Andric std::swap(__z, __x); 11930b57cec5SDimitry Andric __s += 64; 11940b57cec5SDimitry Andric __len -= 64; 11950b57cec5SDimitry Andric } while (__len != 0); 11960b57cec5SDimitry Andric return __hash_len_16( 11970b57cec5SDimitry Andric __hash_len_16(__v.first, __w.first) + __shift_mix(__y) * __k1 + __z, 11980b57cec5SDimitry Andric __hash_len_16(__v.second, __w.second) + __x); 11990b57cec5SDimitry Andric} 12000b57cec5SDimitry Andric 12010b57cec5SDimitry Andrictemplate <class _Tp, size_t = sizeof(_Tp) / sizeof(size_t)> 12020b57cec5SDimitry Andricstruct __scalar_hash; 12030b57cec5SDimitry Andric 12040b57cec5SDimitry Andrictemplate <class _Tp> 12050b57cec5SDimitry Andricstruct __scalar_hash<_Tp, 0> 12060b57cec5SDimitry Andric : public unary_function<_Tp, size_t> 12070b57cec5SDimitry Andric{ 12080b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 12090b57cec5SDimitry Andric size_t operator()(_Tp __v) const _NOEXCEPT 12100b57cec5SDimitry Andric { 12110b57cec5SDimitry Andric union 12120b57cec5SDimitry Andric { 12130b57cec5SDimitry Andric _Tp __t; 12140b57cec5SDimitry Andric size_t __a; 12150b57cec5SDimitry Andric } __u; 12160b57cec5SDimitry Andric __u.__a = 0; 12170b57cec5SDimitry Andric __u.__t = __v; 12180b57cec5SDimitry Andric return __u.__a; 12190b57cec5SDimitry Andric } 12200b57cec5SDimitry Andric}; 12210b57cec5SDimitry Andric 12220b57cec5SDimitry Andrictemplate <class _Tp> 12230b57cec5SDimitry Andricstruct __scalar_hash<_Tp, 1> 12240b57cec5SDimitry Andric : public unary_function<_Tp, size_t> 12250b57cec5SDimitry Andric{ 12260b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 12270b57cec5SDimitry Andric size_t operator()(_Tp __v) const _NOEXCEPT 12280b57cec5SDimitry Andric { 12290b57cec5SDimitry Andric union 12300b57cec5SDimitry Andric { 12310b57cec5SDimitry Andric _Tp __t; 12320b57cec5SDimitry Andric size_t __a; 12330b57cec5SDimitry Andric } __u; 12340b57cec5SDimitry Andric __u.__t = __v; 12350b57cec5SDimitry Andric return __u.__a; 12360b57cec5SDimitry Andric } 12370b57cec5SDimitry Andric}; 12380b57cec5SDimitry Andric 12390b57cec5SDimitry Andrictemplate <class _Tp> 12400b57cec5SDimitry Andricstruct __scalar_hash<_Tp, 2> 12410b57cec5SDimitry Andric : public unary_function<_Tp, size_t> 12420b57cec5SDimitry Andric{ 12430b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 12440b57cec5SDimitry Andric size_t operator()(_Tp __v) const _NOEXCEPT 12450b57cec5SDimitry Andric { 12460b57cec5SDimitry Andric union 12470b57cec5SDimitry Andric { 12480b57cec5SDimitry Andric _Tp __t; 12490b57cec5SDimitry Andric struct 12500b57cec5SDimitry Andric { 12510b57cec5SDimitry Andric size_t __a; 12520b57cec5SDimitry Andric size_t __b; 12530b57cec5SDimitry Andric } __s; 12540b57cec5SDimitry Andric } __u; 12550b57cec5SDimitry Andric __u.__t = __v; 12560b57cec5SDimitry Andric return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u)); 12570b57cec5SDimitry Andric } 12580b57cec5SDimitry Andric}; 12590b57cec5SDimitry Andric 12600b57cec5SDimitry Andrictemplate <class _Tp> 12610b57cec5SDimitry Andricstruct __scalar_hash<_Tp, 3> 12620b57cec5SDimitry Andric : public unary_function<_Tp, size_t> 12630b57cec5SDimitry Andric{ 12640b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 12650b57cec5SDimitry Andric size_t operator()(_Tp __v) const _NOEXCEPT 12660b57cec5SDimitry Andric { 12670b57cec5SDimitry Andric union 12680b57cec5SDimitry Andric { 12690b57cec5SDimitry Andric _Tp __t; 12700b57cec5SDimitry Andric struct 12710b57cec5SDimitry Andric { 12720b57cec5SDimitry Andric size_t __a; 12730b57cec5SDimitry Andric size_t __b; 12740b57cec5SDimitry Andric size_t __c; 12750b57cec5SDimitry Andric } __s; 12760b57cec5SDimitry Andric } __u; 12770b57cec5SDimitry Andric __u.__t = __v; 12780b57cec5SDimitry Andric return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u)); 12790b57cec5SDimitry Andric } 12800b57cec5SDimitry Andric}; 12810b57cec5SDimitry Andric 12820b57cec5SDimitry Andrictemplate <class _Tp> 12830b57cec5SDimitry Andricstruct __scalar_hash<_Tp, 4> 12840b57cec5SDimitry Andric : public unary_function<_Tp, size_t> 12850b57cec5SDimitry Andric{ 12860b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 12870b57cec5SDimitry Andric size_t operator()(_Tp __v) const _NOEXCEPT 12880b57cec5SDimitry Andric { 12890b57cec5SDimitry Andric union 12900b57cec5SDimitry Andric { 12910b57cec5SDimitry Andric _Tp __t; 12920b57cec5SDimitry Andric struct 12930b57cec5SDimitry Andric { 12940b57cec5SDimitry Andric size_t __a; 12950b57cec5SDimitry Andric size_t __b; 12960b57cec5SDimitry Andric size_t __c; 12970b57cec5SDimitry Andric size_t __d; 12980b57cec5SDimitry Andric } __s; 12990b57cec5SDimitry Andric } __u; 13000b57cec5SDimitry Andric __u.__t = __v; 13010b57cec5SDimitry Andric return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u)); 13020b57cec5SDimitry Andric } 13030b57cec5SDimitry Andric}; 13040b57cec5SDimitry Andric 13050b57cec5SDimitry Andricstruct _PairT { 13060b57cec5SDimitry Andric size_t first; 13070b57cec5SDimitry Andric size_t second; 13080b57cec5SDimitry Andric}; 13090b57cec5SDimitry Andric 13100b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY 13110b57cec5SDimitry Andricinline size_t __hash_combine(size_t __lhs, size_t __rhs) _NOEXCEPT { 13120b57cec5SDimitry Andric typedef __scalar_hash<_PairT> _HashT; 13130b57cec5SDimitry Andric const _PairT __p = {__lhs, __rhs}; 13140b57cec5SDimitry Andric return _HashT()(__p); 13150b57cec5SDimitry Andric} 13160b57cec5SDimitry Andric 13170b57cec5SDimitry Andrictemplate<class _Tp> 13180b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS hash<_Tp*> 13190b57cec5SDimitry Andric : public unary_function<_Tp*, size_t> 13200b57cec5SDimitry Andric{ 13210b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13220b57cec5SDimitry Andric size_t operator()(_Tp* __v) const _NOEXCEPT 13230b57cec5SDimitry Andric { 13240b57cec5SDimitry Andric union 13250b57cec5SDimitry Andric { 13260b57cec5SDimitry Andric _Tp* __t; 13270b57cec5SDimitry Andric size_t __a; 13280b57cec5SDimitry Andric } __u; 13290b57cec5SDimitry Andric __u.__t = __v; 13300b57cec5SDimitry Andric return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u)); 13310b57cec5SDimitry Andric } 13320b57cec5SDimitry Andric}; 13330b57cec5SDimitry Andric 13340b57cec5SDimitry Andric 13350b57cec5SDimitry Andrictemplate <> 13360b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS hash<bool> 13370b57cec5SDimitry Andric : public unary_function<bool, size_t> 13380b57cec5SDimitry Andric{ 13390b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13400b57cec5SDimitry Andric size_t operator()(bool __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 13410b57cec5SDimitry Andric}; 13420b57cec5SDimitry Andric 13430b57cec5SDimitry Andrictemplate <> 13440b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS hash<char> 13450b57cec5SDimitry Andric : public unary_function<char, size_t> 13460b57cec5SDimitry Andric{ 13470b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13480b57cec5SDimitry Andric size_t operator()(char __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 13490b57cec5SDimitry Andric}; 13500b57cec5SDimitry Andric 13510b57cec5SDimitry Andrictemplate <> 13520b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS hash<signed char> 13530b57cec5SDimitry Andric : public unary_function<signed char, size_t> 13540b57cec5SDimitry Andric{ 13550b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13560b57cec5SDimitry Andric size_t operator()(signed char __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 13570b57cec5SDimitry Andric}; 13580b57cec5SDimitry Andric 13590b57cec5SDimitry Andrictemplate <> 13600b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS hash<unsigned char> 13610b57cec5SDimitry Andric : public unary_function<unsigned char, size_t> 13620b57cec5SDimitry Andric{ 13630b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13640b57cec5SDimitry Andric size_t operator()(unsigned char __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 13650b57cec5SDimitry Andric}; 13660b57cec5SDimitry Andric 13670b57cec5SDimitry Andric#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS 13680b57cec5SDimitry Andric 13690b57cec5SDimitry Andrictemplate <> 13700b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS hash<char16_t> 13710b57cec5SDimitry Andric : public unary_function<char16_t, size_t> 13720b57cec5SDimitry Andric{ 13730b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13740b57cec5SDimitry Andric size_t operator()(char16_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 13750b57cec5SDimitry Andric}; 13760b57cec5SDimitry Andric 13770b57cec5SDimitry Andrictemplate <> 13780b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS hash<char32_t> 13790b57cec5SDimitry Andric : public unary_function<char32_t, size_t> 13800b57cec5SDimitry Andric{ 13810b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13820b57cec5SDimitry Andric size_t operator()(char32_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 13830b57cec5SDimitry Andric}; 13840b57cec5SDimitry Andric 13850b57cec5SDimitry Andric#endif // _LIBCPP_HAS_NO_UNICODE_CHARS 13860b57cec5SDimitry Andric 13870b57cec5SDimitry Andrictemplate <> 13880b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS hash<wchar_t> 13890b57cec5SDimitry Andric : public unary_function<wchar_t, size_t> 13900b57cec5SDimitry Andric{ 13910b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 13920b57cec5SDimitry Andric size_t operator()(wchar_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 13930b57cec5SDimitry Andric}; 13940b57cec5SDimitry Andric 13950b57cec5SDimitry Andrictemplate <> 13960b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS hash<short> 13970b57cec5SDimitry Andric : public unary_function<short, size_t> 13980b57cec5SDimitry Andric{ 13990b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 14000b57cec5SDimitry Andric size_t operator()(short __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 14010b57cec5SDimitry Andric}; 14020b57cec5SDimitry Andric 14030b57cec5SDimitry Andrictemplate <> 14040b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS hash<unsigned short> 14050b57cec5SDimitry Andric : public unary_function<unsigned short, size_t> 14060b57cec5SDimitry Andric{ 14070b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 14080b57cec5SDimitry Andric size_t operator()(unsigned short __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 14090b57cec5SDimitry Andric}; 14100b57cec5SDimitry Andric 14110b57cec5SDimitry Andrictemplate <> 14120b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS hash<int> 14130b57cec5SDimitry Andric : public unary_function<int, size_t> 14140b57cec5SDimitry Andric{ 14150b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 14160b57cec5SDimitry Andric size_t operator()(int __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 14170b57cec5SDimitry Andric}; 14180b57cec5SDimitry Andric 14190b57cec5SDimitry Andrictemplate <> 14200b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS hash<unsigned int> 14210b57cec5SDimitry Andric : public unary_function<unsigned int, size_t> 14220b57cec5SDimitry Andric{ 14230b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 14240b57cec5SDimitry Andric size_t operator()(unsigned int __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 14250b57cec5SDimitry Andric}; 14260b57cec5SDimitry Andric 14270b57cec5SDimitry Andrictemplate <> 14280b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS hash<long> 14290b57cec5SDimitry Andric : public unary_function<long, size_t> 14300b57cec5SDimitry Andric{ 14310b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 14320b57cec5SDimitry Andric size_t operator()(long __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 14330b57cec5SDimitry Andric}; 14340b57cec5SDimitry Andric 14350b57cec5SDimitry Andrictemplate <> 14360b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS hash<unsigned long> 14370b57cec5SDimitry Andric : public unary_function<unsigned long, size_t> 14380b57cec5SDimitry Andric{ 14390b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 14400b57cec5SDimitry Andric size_t operator()(unsigned long __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 14410b57cec5SDimitry Andric}; 14420b57cec5SDimitry Andric 14430b57cec5SDimitry Andrictemplate <> 14440b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS hash<long long> 14450b57cec5SDimitry Andric : public __scalar_hash<long long> 14460b57cec5SDimitry Andric{ 14470b57cec5SDimitry Andric}; 14480b57cec5SDimitry Andric 14490b57cec5SDimitry Andrictemplate <> 14500b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS hash<unsigned long long> 14510b57cec5SDimitry Andric : public __scalar_hash<unsigned long long> 14520b57cec5SDimitry Andric{ 14530b57cec5SDimitry Andric}; 14540b57cec5SDimitry Andric 14550b57cec5SDimitry Andric#ifndef _LIBCPP_HAS_NO_INT128 14560b57cec5SDimitry Andric 14570b57cec5SDimitry Andrictemplate <> 14580b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS hash<__int128_t> 14590b57cec5SDimitry Andric : public __scalar_hash<__int128_t> 14600b57cec5SDimitry Andric{ 14610b57cec5SDimitry Andric}; 14620b57cec5SDimitry Andric 14630b57cec5SDimitry Andrictemplate <> 14640b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS hash<__uint128_t> 14650b57cec5SDimitry Andric : public __scalar_hash<__uint128_t> 14660b57cec5SDimitry Andric{ 14670b57cec5SDimitry Andric}; 14680b57cec5SDimitry Andric 14690b57cec5SDimitry Andric#endif 14700b57cec5SDimitry Andric 14710b57cec5SDimitry Andrictemplate <> 14720b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS hash<float> 14730b57cec5SDimitry Andric : public __scalar_hash<float> 14740b57cec5SDimitry Andric{ 14750b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 14760b57cec5SDimitry Andric size_t operator()(float __v) const _NOEXCEPT 14770b57cec5SDimitry Andric { 14780b57cec5SDimitry Andric // -0.0 and 0.0 should return same hash 14790b57cec5SDimitry Andric if (__v == 0.0f) 14800b57cec5SDimitry Andric return 0; 14810b57cec5SDimitry Andric return __scalar_hash<float>::operator()(__v); 14820b57cec5SDimitry Andric } 14830b57cec5SDimitry Andric}; 14840b57cec5SDimitry Andric 14850b57cec5SDimitry Andrictemplate <> 14860b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS hash<double> 14870b57cec5SDimitry Andric : public __scalar_hash<double> 14880b57cec5SDimitry Andric{ 14890b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 14900b57cec5SDimitry Andric size_t operator()(double __v) const _NOEXCEPT 14910b57cec5SDimitry Andric { 14920b57cec5SDimitry Andric // -0.0 and 0.0 should return same hash 14930b57cec5SDimitry Andric if (__v == 0.0) 14940b57cec5SDimitry Andric return 0; 14950b57cec5SDimitry Andric return __scalar_hash<double>::operator()(__v); 14960b57cec5SDimitry Andric } 14970b57cec5SDimitry Andric}; 14980b57cec5SDimitry Andric 14990b57cec5SDimitry Andrictemplate <> 15000b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS hash<long double> 15010b57cec5SDimitry Andric : public __scalar_hash<long double> 15020b57cec5SDimitry Andric{ 15030b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 15040b57cec5SDimitry Andric size_t operator()(long double __v) const _NOEXCEPT 15050b57cec5SDimitry Andric { 15060b57cec5SDimitry Andric // -0.0 and 0.0 should return same hash 15070b57cec5SDimitry Andric if (__v == 0.0L) 15080b57cec5SDimitry Andric return 0; 15090b57cec5SDimitry Andric#if defined(__i386__) 15100b57cec5SDimitry Andric // Zero out padding bits 15110b57cec5SDimitry Andric union 15120b57cec5SDimitry Andric { 15130b57cec5SDimitry Andric long double __t; 15140b57cec5SDimitry Andric struct 15150b57cec5SDimitry Andric { 15160b57cec5SDimitry Andric size_t __a; 15170b57cec5SDimitry Andric size_t __b; 15180b57cec5SDimitry Andric size_t __c; 15190b57cec5SDimitry Andric size_t __d; 15200b57cec5SDimitry Andric } __s; 15210b57cec5SDimitry Andric } __u; 15220b57cec5SDimitry Andric __u.__s.__a = 0; 15230b57cec5SDimitry Andric __u.__s.__b = 0; 15240b57cec5SDimitry Andric __u.__s.__c = 0; 15250b57cec5SDimitry Andric __u.__s.__d = 0; 15260b57cec5SDimitry Andric __u.__t = __v; 15270b57cec5SDimitry Andric return __u.__s.__a ^ __u.__s.__b ^ __u.__s.__c ^ __u.__s.__d; 15280b57cec5SDimitry Andric#elif defined(__x86_64__) 15290b57cec5SDimitry Andric // Zero out padding bits 15300b57cec5SDimitry Andric union 15310b57cec5SDimitry Andric { 15320b57cec5SDimitry Andric long double __t; 15330b57cec5SDimitry Andric struct 15340b57cec5SDimitry Andric { 15350b57cec5SDimitry Andric size_t __a; 15360b57cec5SDimitry Andric size_t __b; 15370b57cec5SDimitry Andric } __s; 15380b57cec5SDimitry Andric } __u; 15390b57cec5SDimitry Andric __u.__s.__a = 0; 15400b57cec5SDimitry Andric __u.__s.__b = 0; 15410b57cec5SDimitry Andric __u.__t = __v; 15420b57cec5SDimitry Andric return __u.__s.__a ^ __u.__s.__b; 15430b57cec5SDimitry Andric#else 15440b57cec5SDimitry Andric return __scalar_hash<long double>::operator()(__v); 15450b57cec5SDimitry Andric#endif 15460b57cec5SDimitry Andric } 15470b57cec5SDimitry Andric}; 15480b57cec5SDimitry Andric 15490b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 15500b57cec5SDimitry Andric 15510b57cec5SDimitry Andrictemplate <class _Tp, bool = is_enum<_Tp>::value> 15520b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS __enum_hash 15530b57cec5SDimitry Andric : public unary_function<_Tp, size_t> 15540b57cec5SDimitry Andric{ 15550b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 15560b57cec5SDimitry Andric size_t operator()(_Tp __v) const _NOEXCEPT 15570b57cec5SDimitry Andric { 15580b57cec5SDimitry Andric typedef typename underlying_type<_Tp>::type type; 15590b57cec5SDimitry Andric return hash<type>{}(static_cast<type>(__v)); 15600b57cec5SDimitry Andric } 15610b57cec5SDimitry Andric}; 15620b57cec5SDimitry Andrictemplate <class _Tp> 15630b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS __enum_hash<_Tp, false> { 15640b57cec5SDimitry Andric __enum_hash() = delete; 15650b57cec5SDimitry Andric __enum_hash(__enum_hash const&) = delete; 15660b57cec5SDimitry Andric __enum_hash& operator=(__enum_hash const&) = delete; 15670b57cec5SDimitry Andric}; 15680b57cec5SDimitry Andric 15690b57cec5SDimitry Andrictemplate <class _Tp> 15700b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS hash : public __enum_hash<_Tp> 15710b57cec5SDimitry Andric{ 15720b57cec5SDimitry Andric}; 15730b57cec5SDimitry Andric#endif 15740b57cec5SDimitry Andric 15750b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 15760b57cec5SDimitry Andric 15770b57cec5SDimitry Andrictemplate <> 15780b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS hash<nullptr_t> 15790b57cec5SDimitry Andric : public unary_function<nullptr_t, size_t> 15800b57cec5SDimitry Andric{ 15810b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 15820b57cec5SDimitry Andric size_t operator()(nullptr_t) const _NOEXCEPT { 15830b57cec5SDimitry Andric return 662607004ull; 15840b57cec5SDimitry Andric } 15850b57cec5SDimitry Andric}; 15860b57cec5SDimitry Andric#endif 15870b57cec5SDimitry Andric 15880b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 15890b57cec5SDimitry Andrictemplate <class _Key, class _Hash> 15900b57cec5SDimitry Andricusing __check_hash_requirements _LIBCPP_NODEBUG_TYPE = integral_constant<bool, 15910b57cec5SDimitry Andric is_copy_constructible<_Hash>::value && 15920b57cec5SDimitry Andric is_move_constructible<_Hash>::value && 15930b57cec5SDimitry Andric __invokable_r<size_t, _Hash, _Key const&>::value 15940b57cec5SDimitry Andric>; 15950b57cec5SDimitry Andric 15960b57cec5SDimitry Andrictemplate <class _Key, class _Hash = std::hash<_Key> > 15970b57cec5SDimitry Andricusing __has_enabled_hash _LIBCPP_NODEBUG_TYPE = integral_constant<bool, 15980b57cec5SDimitry Andric __check_hash_requirements<_Key, _Hash>::value && 15990b57cec5SDimitry Andric is_default_constructible<_Hash>::value 16000b57cec5SDimitry Andric>; 16010b57cec5SDimitry Andric 16020b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 16030b57cec5SDimitry Andrictemplate <class _Type, class> 16040b57cec5SDimitry Andricusing __enable_hash_helper_imp _LIBCPP_NODEBUG_TYPE = _Type; 16050b57cec5SDimitry Andric 16060b57cec5SDimitry Andrictemplate <class _Type, class ..._Keys> 16070b57cec5SDimitry Andricusing __enable_hash_helper _LIBCPP_NODEBUG_TYPE = __enable_hash_helper_imp<_Type, 16080b57cec5SDimitry Andric typename enable_if<__all<__has_enabled_hash<_Keys>::value...>::value>::type 16090b57cec5SDimitry Andric>; 16100b57cec5SDimitry Andric#else 16110b57cec5SDimitry Andrictemplate <class _Type, class ...> 16120b57cec5SDimitry Andricusing __enable_hash_helper _LIBCPP_NODEBUG_TYPE = _Type; 16130b57cec5SDimitry Andric#endif 16140b57cec5SDimitry Andric 16150b57cec5SDimitry Andric#endif // !_LIBCPP_CXX03_LANG 16160b57cec5SDimitry Andric 16170b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD 16180b57cec5SDimitry Andric 16190b57cec5SDimitry Andric#endif // _LIBCPP_UTILITY 1620