MSTL 1.4.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
pair< T1, T2 > 模板类 参考

存储两个值的元组对 更多...

#include <pair.hpp>

类 pair< T1, T2 > 继承关系图:
[图例]

Public 类型

using first_type = T1
 第一个元素的类型
using second_type = T2
 第二个元素的类型

Public 成员函数

template<typename U1 = T1, typename U2 = T2, enable_if_t< conjunction< is_default_constructible< U1 >, is_default_constructible< U2 > >::value &&!conjunction< is_implicitly_default_constructible< U1 >, is_implicitly_default_constructible< U2 > >::value, int > = 0>
 pair () noexcept(conjunction< is_nothrow_default_constructible< U1 >, is_nothrow_default_constructible< U2 > >::value)
 显式默认构造函数
template<typename U1 = T1, typename U2 = T2, enable_if_t< conjunction< is_default_constructible< U1 >, is_default_constructible< U2 > >::value &&conjunction< is_implicitly_default_constructible< U1 >, is_implicitly_default_constructible< U2 > >::value, int > = 0>
 pair () noexcept(conjunction< is_nothrow_default_constructible< U1 >, is_nothrow_default_constructible< U2 > >::value)
 隐式默认构造函数
template<typename U1 = T1, typename U2 = T2, enable_if_t< conjunction< is_copy_constructible< U1 >, is_copy_constructible< U2 > >::value &&!conjunction< is_convertible< const U1 &, U1 >, is_convertible< const U2 &, U2 > >::value, int > = 0>
 pair (const T1 &a, const T2 &b) noexcept(conjunction< is_nothrow_copy_constructible< U1 >, is_nothrow_copy_constructible< U2 > >::value)
 显式拷贝构造函数
template<typename U1 = T1, typename U2 = T2, enable_if_t< conjunction< is_copy_constructible< U1 >, is_copy_constructible< U2 > >::value &&conjunction< is_convertible< const U1 &, U1 >, is_convertible< const U2 &, U2 > >::value, int > = 0>
 pair (const T1 &a, const T2 &b) noexcept(conjunction< is_nothrow_copy_constructible< U1 >, is_nothrow_copy_constructible< U2 > >::value)
 隐式拷贝构造函数
template<typename U1, typename U2, enable_if_t< conjunction< is_constructible< T1, U1 >, is_constructible< T2, U2 > >::value &&!conjunction< is_convertible< U1, T1 >, is_convertible< U2, T2 > >::value, int > = 0>
 pair (U1 &&a, U2 &&b) noexcept(conjunction< is_nothrow_constructible< T1, U1 >, is_nothrow_constructible< T2, U2 > >::value)
 显式通用值构造函数
template<typename U1, typename U2, enable_if_t< conjunction< is_constructible< T1, U1 >, is_constructible< T2, U2 > >::value &&conjunction< is_convertible< U1, T1 >, is_convertible< U2, T2 > >::value, int > = 0>
 pair (U1 &&a, U2 &&b) noexcept(conjunction< is_nothrow_constructible< T1, U1 >, is_nothrow_constructible< T2, U2 > >::value)
 隐式通用值构造函数
template<typename U1, typename U2, enable_if_t< conjunction< is_constructible< T1, const U1 & >, is_constructible< T2, const U2 & > >::value &&!conjunction< is_convertible< const U1 &, T1 >, is_convertible< const U2 &, T2 > >::value, int > = 0>
 pair (const pair< U1, U2 > &p) noexcept(conjunction< is_nothrow_constructible< T1, const U1 & >, is_nothrow_constructible< T2, const U2 & > >::value)
 显式拷贝pair构造函数
template<typename U1, typename U2, enable_if_t< conjunction< is_constructible< T1, const U1 & >, is_constructible< T2, const U2 & > >::value &&conjunction< is_convertible< const U1 &, T1 >, is_convertible< const U2 &, T2 > >::value, int > = 0>
 pair (const pair< U1, U2 > &p) noexcept(conjunction< is_nothrow_constructible< T1, const U1 & >, is_nothrow_constructible< T2, const U2 & > >::value)
 隐式拷贝pair构造函数
template<typename U1, typename U2, enable_if_t< conjunction< is_constructible< T1, U1 >, is_constructible< T2, U2 > >::value &&!conjunction< is_convertible< U1, T1 >, is_convertible< U2, T2 > >::value, int > = 0>
 pair (pair< U1, U2 > &&p) noexcept(conjunction< is_nothrow_constructible< T1, U1 >, is_nothrow_constructible< T2, U2 > >::value)
 显式移动pair构造函数
template<typename U1, typename U2, enable_if_t< conjunction< is_constructible< T1, U1 >, is_constructible< T2, U2 > >::value &&conjunction< is_convertible< U1, T1 >, is_convertible< U2, T2 > >::value, int > = 0>
 pair (pair< U1, U2 > &&p) noexcept(conjunction< is_nothrow_constructible< T1, U1 >, is_nothrow_constructible< T2, U2 > >::value)
 隐式移动pair构造函数
 pair (const pair &p)=default
 默认拷贝构造函数
 pair (pair &&p)=default
 默认移动构造函数
template<typename Tuple1, typename Tuple2, size_t... Index1, size_t... Index2>
constexpr pair (Tuple1 &t1, Tuple2 &t2, index_sequence< Index1... > idx1, index_sequence< Index2... > idx2)
 从两个tuple构造pair
template<typename... Types1, typename... Types2>
constexpr pair (unpack_utility_construct_tag, tuple< Types1... > t1, tuple< Types2... > t2)
 从两个tuple构造pair
template<typename T = pair, enable_if_t< conjunction< is_copy_assignable< typename T::first_type >, is_copy_assignable< typename T::second_type > >::value, int > = 0>
MSTL_CONSTEXPR14 pairoperator= (type_identity_t< const T & > p) noexcept(conjunction< is_nothrow_copy_assignable< T1 >, is_nothrow_copy_assignable< T2 > >::value)
 拷贝赋值运算符
template<typename T = pair, enable_if_t< conjunction< is_move_assignable< typename T::first_type >, is_move_assignable< typename T::second_type > >::value, int > = 0>
MSTL_CONSTEXPR14 pairoperator= (type_identity_t< T && > p) noexcept(conjunction< is_nothrow_move_assignable< T1 >, is_nothrow_move_assignable< T2 > >::value)
 移动赋值运算符
template<typename U1, typename U2, enable_if_t< conjunction< negation< is_same< pair, pair< U1, U2 > > >, is_assignable< T1 &, const U1 & >, is_assignable< T2 &, const U2 & > >::value, int > = 0>
MSTL_CONSTEXPR14 pairoperator= (const pair< U1, U2 > &p) noexcept(conjunction< is_nothrow_assignable< T1 &, const U1 & >, is_nothrow_assignable< T2 &, const U2 & > >::value)
 从不同类型pair的拷贝赋值运算符
template<typename U1, typename U2, enable_if_t< conjunction< negation< is_same< pair, pair< U1, U2 > > >, is_assignable< T1 &, U1 >, is_assignable< T2 &, U2 > >::value, int > = 0>
MSTL_CONSTEXPR14 pairoperator= (pair< U1, U2 > &&p) noexcept(conjunction< is_nothrow_assignable< T1 &, U1 >, is_nothrow_assignable< T2 &, U2 > >::value)
 从不同类型pair的移动赋值运算符
pairoperator= (const volatile pair &)=delete
 禁止volatile拷贝赋值
MSTL_CONSTEXPR20 ~pair ()=default
 析构函数
constexpr bool operator== (const pair &y) const noexcept(noexcept(this->first==y.first &&this->second==y.second))
 相等比较运算符
constexpr bool operator< (const pair &y) const noexcept(noexcept(this->first< y.first||(!(y.first< this->first) &&this->second< y.second)))
 小于比较运算符
MSTL_NODISCARD constexpr size_t to_hash () const noexcept(noexcept(hash< remove_cvref_t< T1 > >()(first) ^ hash< remove_cvref_t< T2 > >()(second)))
 计算hash值
MSTL_CONSTEXPR14 void swap (pair &p) noexcept(conjunction< is_nothrow_swappable< T1 >, is_nothrow_swappable< T2 > >::value)
 交换两个pair的内容
Public 成员函数 继承自 icomparable< pair< T1, T2 > >
MSTL_NODISCARD constexpr bool operator== (const pair< T1, T2 > &rhs) const noexcept(noexcept(derived()==rhs))
 相等比较运算符
MSTL_NODISCARD constexpr bool operator!= (const pair< T1, T2 > &rhs) const noexcept(noexcept(!(*this==rhs)))
 不等比较运算符
MSTL_NODISCARD constexpr bool operator< (const pair< T1, T2 > &rhs) const noexcept(noexcept(derived()< rhs))
 小于比较运算符
MSTL_NODISCARD constexpr bool operator> (const pair< T1, T2 > &rhs) const noexcept(noexcept(rhs< derived()))
 大于比较运算符
MSTL_NODISCARD constexpr bool operator<= (const pair< T1, T2 > &rhs) const noexcept(noexcept(!(derived() > rhs)))
 小于等于比较运算符
MSTL_NODISCARD constexpr bool operator>= (const pair< T1, T2 > &rhs) const noexcept(noexcept(!(derived()< rhs)))
 大于等于比较运算符
Public 成员函数 继承自 ihashable< pair< T1, T2 > >
MSTL_NODISCARD constexpr size_t to_hash () const noexcept(noexcept(derived().to_hash()))
 获取对象的哈希值

Public 属性

T1 first
 第一个元素
T2 second
 第二个元素

详细描述

template<typename T1, typename T2>
class pair< T1, T2 >

存储两个值的元组对

模板参数
T1第一个元素的类型
T2第二个元素的类型

pair是一个可以存储两个不同类型的值的模板类,常用于返回多个值。 支持tuple-like接口,可用于结构化绑定。

在文件 pair.hpp90 行定义.

构造及析构函数说明

◆ pair() [1/2]

template<typename T1, typename T2>
template<typename Tuple1, typename Tuple2, size_t... Index1, size_t... Index2>
pair< T1, T2 >::pair ( Tuple1 & t1,
Tuple2 & t2,
index_sequence< Index1... > idx1,
index_sequence< Index2... > idx2 )
inlineconstexpr

从两个tuple构造pair

模板参数
Tuple1第一个tuple的类型
Tuple2第二个tuple的类型
Index1第一个tuple的索引序列
Index2第二个tuple的索引序列
参数
t1第一个tuple
t2第二个tuple
idx1第一个tuple的索引序列
idx2第二个tuple的索引序列

内部构造函数,用于从tuple构造pair

在文件 pair.hpp295 行定义.

◆ pair() [2/2]

template<typename T1, typename T2>
template<typename... Types1, typename... Types2>
pair< T1, T2 >::pair ( unpack_utility_construct_tag ,
tuple< Types1... > t1,
tuple< Types2... > t2 )
inlineconstexpr

从两个tuple构造pair

模板参数
Types1第一个tuple的元素类型
Types2第二个tuple的元素类型
参数
t1第一个tuple
t2第二个tuple

标签分发构造函数,用于从tuple构造pair

在文件 pair.hpp309 行定义.

成员函数说明

◆ operator<()

template<typename T1, typename T2>
bool pair< T1, T2 >::operator< ( const pair< T1, T2 > & y) const
inlineconstexprnoexcept

小于比较运算符

参数
y要比较的pair
返回
比较结果

先比较first,如果相等则比较second

在文件 pair.hpp397 行定义.

◆ operator=() [1/4]

template<typename T1, typename T2>
template<typename U1, typename U2, enable_if_t< conjunction< negation< is_same< pair, pair< U1, U2 > > >, is_assignable< T1 &, const U1 & >, is_assignable< T2 &, const U2 & > >::value, int > = 0>
MSTL_CONSTEXPR14 pair & pair< T1, T2 >::operator= ( const pair< U1, U2 > & p)
inlinenoexcept

从不同类型pair的拷贝赋值运算符

模板参数
U1源pair第一个元素的类型
U2源pair第二个元素的类型
参数
p源pair
返回
当前pair的引用

在文件 pair.hpp351 行定义.

◆ operator=() [2/4]

template<typename T1, typename T2>
template<typename U1, typename U2, enable_if_t< conjunction< negation< is_same< pair, pair< U1, U2 > > >, is_assignable< T1 &, U1 >, is_assignable< T2 &, U2 > >::value, int > = 0>
MSTL_CONSTEXPR14 pair & pair< T1, T2 >::operator= ( pair< U1, U2 > && p)
inlinenoexcept

从不同类型pair的移动赋值运算符

模板参数
U1源pair第一个元素的类型
U2源pair第二个元素的类型
参数
p源pair
返回
当前pair的引用

在文件 pair.hpp367 行定义.

◆ operator=() [3/4]

template<typename T1, typename T2>
template<typename T = pair, enable_if_t< conjunction< is_copy_assignable< typename T::first_type >, is_copy_assignable< typename T::second_type > >::value, int > = 0>
MSTL_CONSTEXPR14 pair & pair< T1, T2 >::operator= ( type_identity_t< const T & > p)
inlinenoexcept

拷贝赋值运算符

模板参数
Tpair类型,用于SFINAE
参数
p源pair
返回
当前pair的引用

在文件 pair.hpp320 行定义.

◆ operator=() [4/4]

template<typename T1, typename T2>
template<typename T = pair, enable_if_t< conjunction< is_move_assignable< typename T::first_type >, is_move_assignable< typename T::second_type > >::value, int > = 0>
MSTL_CONSTEXPR14 pair & pair< T1, T2 >::operator= ( type_identity_t< T && > p)
inlinenoexcept

移动赋值运算符

模板参数
Tpair类型,用于SFINAE
参数
p源pair
返回
当前pair的引用

在文件 pair.hpp335 行定义.

◆ operator==()

template<typename T1, typename T2>
bool pair< T1, T2 >::operator== ( const pair< T1, T2 > & y) const
inlineconstexprnoexcept

相等比较运算符

参数
y要比较的pair
返回
比较结果

如果两个pair的所有元素都相等则返回true

在文件 pair.hpp385 行定义.

◆ swap()

template<typename T1, typename T2>
MSTL_CONSTEXPR14 void pair< T1, T2 >::swap ( pair< T1, T2 > & p)
inlinenoexcept

交换两个pair的内容

参数
p要交换的pair

在文件 pair.hpp417 行定义.

◆ to_hash()

template<typename T1, typename T2>
MSTL_NODISCARD constexpr size_t pair< T1, T2 >::to_hash ( ) const
inlineconstexprnoexcept

计算hash值

返回
pair的hash值

使用两个元素的hash值进行异或操作

在文件 pair.hpp408 行定义.


该类的文档由以下文件生成: