1#ifndef MSTL_CORE_UTILITY_PAIR_HPP__
2#define MSTL_CORE_UTILITY_PAIR_HPP__
22#ifdef MSTL_STANDARD_14__
35template <
size_t Index,
typename... Tuple>
45template <
size_t Index,
typename... Types>
53template <
size_t Index,
typename... Types>
56template <
size_t Index,
typename... Types>
57MSTL_NODISCARD
constexpr tuple_element_t<Index, Types...>&
get(tuple<Types...>& t)
noexcept;
58template <
size_t Index,
typename... Types>
59MSTL_NODISCARD
constexpr const tuple_element_t<Index, Types...>&
get(
const tuple<Types...>& t)
noexcept;
60template <
size_t Index,
typename... Types>
61MSTL_NODISCARD
constexpr tuple_element_t<Index, Types...>&&
get(tuple<Types...>&& t)
noexcept;
62template <
size_t Index,
typename... Types>
63MSTL_NODISCARD
constexpr const tuple_element_t<Index, Types...>&&
get(
const tuple<Types...>&& t)
noexcept;
67template <
size_t Index,
typename... Types>
69__pair_get_from_tuple(tuple<Types...>&& t)
noexcept;
89template <
typename T1,
typename T2>
97#ifdef MSTL_STANDARD_20__
105 template <
typename U1 = T1,
typename U2 = T2,
enable_if_t<
107 constexpr explicit(!conjunction_v<
109 pair()
noexcept(conjunction_v<
122 template <
typename U1 = T1,
typename U2 = T2,
enable_if_t<
125 pair(
const T1& a,
const T2& b)
noexcept(conjunction_v<
139 conjunction_v<is_constructible<T1, U1>, is_constructible<T2, U2>>,
int> = 0>
140 constexpr explicit(!conjunction_v<is_convertible<U1, T1>, is_convertible<U2, T2>>)
141 pair(U1&& a, U2&& b)
noexcept(conjunction_v<
142 is_nothrow_constructible<T1, U1>, is_nothrow_constructible<T2, U2>>)
154 conjunction_v<is_constructible<T1, const U1&>, is_constructible<T2, const U2&>>,
int> = 0>
155 constexpr explicit(!conjunction_v<is_convertible<const U1&, T1>, is_convertible<const U2&, T2>>)
157 is_nothrow_constructible<T1, const U1&>, is_nothrow_constructible<T2, const U2&>>)
169 conjunction_v<is_constructible<T1, U1>, is_constructible<T2, U2>>,
int> = 0>
170 constexpr explicit(!conjunction_v<
171 is_convertible<U1, T1>, is_convertible<U2, T2>>)
173 is_nothrow_constructible<T1, U1>, is_nothrow_constructible<T2, U2>>)
179 template <
typename U1 = T1,
typename U2 = T2,
enable_if_t<
180 conjunction<is_default_constructible<U1>, is_default_constructible<U2>>::value &&
181 !conjunction<is_implicitly_default_constructible<U1>,
182 is_implicitly_default_constructible<U2>>::value,
int> = 0>
189 template <
typename U1 = T1,
typename U2 = T2,
enable_if_t<
200 template <
typename U1 = T1,
typename U2 = T2,
enable_if_t<
210 template <
typename U1 = T1,
typename U2 = T2,
enable_if_t<
294 template <
typename Tuple1,
typename Tuple2,
size_t... Index1,
size_t... Index2>
308 template <
typename... Types1,
typename... Types2>
319 is_copy_assignable<typename T::first_type>, is_copy_assignable<typename T::second_type>>::value,
int> = 0>
386 noexcept(
noexcept(this->
first == y.first && this->
second == y.second)) {
387 return this->
first == y.first && this->
second == y.second;
398 noexcept(
noexcept(this->
first < y.first || (!(y.first < this->
first) && this->
second < y.second))) {
399 return this->
first < y.first || (!(y.first < this->
first) && this->
second < y.second);
408 MSTL_NODISCARD
constexpr size_t to_hash() const
424#if MSTL_SUPPORT_DEDUCTION_GUIDES__
425template <
typename T1,
typename T2>
440template <
typename T1,
typename T2>
461template <
typename... Types>
469template <
size_t Index>
477template <
typename This,
typename... Rest>
480 using tuple_type = tuple<This, Rest...>;
489template <
size_t Index,
typename This,
typename... Rest>
499template <
size_t Index,
typename... Types>
508template <
typename T1,
typename T2>
517template <
size_t Index,
typename T1,
typename T2>
519 static_assert(Index < 2,
"pair element index out of range.");
526#ifndef MSTL_STANDARD_17__
530template <
size_t Index,
typename T1,
typename T2>
531struct __pair_get_helper;
532template <
typename T1,
typename T2>
533struct __pair_get_helper<0, T1, T2> {
539 get(
const pair<T1, T2>& pir)
noexcept {
543 get(pair<T1, T2>&& pir)
noexcept {
547 get(
const pair<T1, T2>&& pir)
noexcept {
552template <
typename T1,
typename T2>
553struct __pair_get_helper<1, T1, T2> {
555 get(pair<T1, T2>& pir)
noexcept {
559 get(
const pair<T1, T2>& pir)
noexcept {
563 get(pair<T1, T2>&& pir)
noexcept {
567 get(
const pair<T1, T2>&& pir)
noexcept {
579template <
size_t Index,
typename T1,
typename T2>
583#ifdef MSTL_STANDARD_17__
584template <
size_t Index,
typename T1,
typename T2>
587 if constexpr (Index == 0) {
594template <
size_t Index,
typename T1,
typename T2>
597 return _INNER __pair_get_helper<Index, T1, T2>::get(pir);
604template <
typename T1,
typename T2>
612template <
typename T2,
typename T1>
621template <
size_t Index,
typename T1,
typename T2>
625#ifdef MSTL_STANDARD_17__
626template <
size_t Index,
typename T1,
typename T2>
629 if constexpr (Index == 0)
635template <
size_t Index,
typename T1,
typename T2>
638 return _INNER __pair_get_helper<Index, T1, T2>::get(pir);
645template <
typename T1,
typename T2>
653template <
typename T2,
typename T1>
662template <
size_t Index,
typename T1,
typename T2>
666#ifdef MSTL_STANDARD_17__
667template <
size_t Index,
typename T1,
typename T2>
670 if constexpr (Index == 0)
676template <
size_t Index,
typename T1,
typename T2>
687template <
typename T1,
typename T2>
695template <
typename T2,
typename T1>
704template <
size_t Index,
typename T1,
typename T2>
708#ifdef MSTL_STANDARD_17__
709template <
size_t Index,
typename T1,
typename T2>
712 if constexpr (Index == 0)
718template <
size_t Index,
typename T1,
typename T2>
729template <
typename T1,
typename T2>
737template <
typename T2,
typename T1>
749 template <
typename T>
752 template <_MSTL
size_t I,
typename T>
753 struct tuple_element;
755 template <
typename T1,
typename T2>
756 struct tuple_size<
_MSTL pair<T1, T2>> :
_MSTL integral_constant<_MSTL size_t, 2> {};
758 template <_MSTL
size_t I,
typename T1,
typename T2>
759 struct tuple_element<I,
_MSTL pair<T1, T2>> {
MSTL_NODISCARD constexpr T && forward(remove_reference_t< T > &x) noexcept
完美转发左值
MSTL_ALWAYS_INLINE enable_if_t< is_void_v< T >, future_result_t< T > > get(future< T > &f)
通用future结果获取函数
integer_sequence< size_t, Values... > index_sequence
索引序列
make_index_sequence< sizeof...(Types)> index_sequence_for
根据类型参数包生成索引序列
#define _MSTL
全局命名空间MSTL前缀
#define MSTL_END_INNER__
结束inner命名空间
#define _INNER
inner命名空间前缀
#define MSTL_END_NAMESPACE__
结束全局命名空间MSTL
#define MSTL_BEGIN_NAMESPACE__
开始全局命名空间MSTL
#define MSTL_BEGIN_INNER__
开始inner命名空间
constexpr pair< unwrap_ref_decay_t< T1 >, unwrap_ref_decay_t< T2 > > make_pair(T1 &&x, T2 &&y) noexcept(conjunction< is_nothrow_constructible< unwrap_ref_decay_t< T1 >, T1 >, is_nothrow_constructible< unwrap_ref_decay_t< T2 >, T2 > >::value)
创建pair的辅助函数
typename unwrap_ref_decay< T >::type unwrap_ref_decay_t
unwrap_ref_decay的便捷别名
typename remove_cvref< T >::type remove_cvref_t
remove_cvref的便捷别名
constexpr Iterator2 move(Iterator1 first, Iterator1 last, Iterator2 result)
移动范围元素
void swap()=delete
删除无参数的swap重载
MSTL_NODISCARD constexpr tuple_element_t< Index, Types... > & get(tuple< Types... > &t) noexcept
获取元组中指定位置的元素引用
typename conditional< Test, T1, T2 >::type conditional_t
conditional的便捷别名
typename type_identity< T >::type type_identity_t
type_identity的便捷别名
typename enable_if< Test, T >::type enable_if_t
enable_if的便捷别名
typename tuple_element< Index, Types... >::tuple_type tuple_extract_base_t
获取tuple元素基类型的类型别名
typename tuple_element< Index, Types... >::type tuple_element_t
tuple_element的类型别名
pair() noexcept(conjunction< is_nothrow_default_constructible< U1 >, is_nothrow_default_constructible< U2 > >::value)
显式默认构造函数
constexpr pair(Tuple1 &t1, Tuple2 &t2, index_sequence< Index1... > idx1, index_sequence< Index2... > idx2)
从两个tuple构造pair
pair(pair< U1, U2 > &&p) noexcept(conjunction< is_nothrow_constructible< T1, U1 >, is_nothrow_constructible< T2, U2 > >::value)
显式移动pair构造函数
MSTL_CONSTEXPR14 void swap(pair &p) noexcept(conjunction< is_nothrow_swappable< T1 >, is_nothrow_swappable< T2 > >::value)
交换两个pair的内容
constexpr bool operator<(const pair &y) const noexcept(noexcept(this->first< y.first||(!(y.first< this->first) &&this->second< y.second)))
小于比较运算符
pair(const pair< U1, U2 > &p) noexcept(conjunction< is_nothrow_constructible< T1, const U1 & >, is_nothrow_constructible< T2, const U2 & > >::value)
显式拷贝pair构造函数
pair(const pair &p)=default
默认拷贝构造函数
MSTL_CONSTEXPR20 ~pair()=default
析构函数
constexpr pair(unpack_utility_construct_tag, tuple< Types1... > t1, tuple< Types2... > t2)
从两个tuple构造pair
pair(const T1 &a, const T2 &b) noexcept(conjunction< is_nothrow_copy_constructible< U1 >, is_nothrow_copy_constructible< U2 > >::value)
显式拷贝构造函数
MSTL_CONSTEXPR14 pair & operator=(type_identity_t< const T & > p) noexcept(conjunction< is_nothrow_copy_assignable< T1 >, is_nothrow_copy_assignable< T2 > >::value)
拷贝赋值运算符
MSTL_NODISCARD constexpr size_t to_hash() const noexcept(noexcept(hash< remove_cvref_t< T1 > >()(first) ^ hash< remove_cvref_t< T2 > >()(second)))
计算hash值
constexpr bool operator==(const pair &y) const noexcept(noexcept(this->first==y.first &&this->second==y.second))
相等比较运算符
pair(pair &&p)=default
默认移动构造函数
pair(U1 &&a, U2 &&b) noexcept(conjunction< is_nothrow_constructible< T1, U1 >, is_nothrow_constructible< T2, U2 > >::value)
显式通用值构造函数
conditional_t< Index==0, T1, T2 > type
根据索引返回对应类型
tuple< T1, T2 > tuple_type
对应的tuple类型