在线文档教程
C++
应用 | Utilities

std::pair

STD:一对

Defined in header
template< class T1, class T2 > struct pair;

std::pair是一个struct模板,它提供了将两个异构对象作为一个单元存储的方法。对是std::tuple有两个元素。

If std::is_trivially_destructible_v && std::is_trivially_destructible_v is true, the destructor of pair is trivial.(since C++17)

模板参数

T1, T2-the types of the elements that the pair stores.

成员类型

Member typeDefinition
first_typeT1
second_typeT2

成员对象

Member nameType
firstT1
secondT2

成员函数

(constructor)constructs new pair (public member function)
operator=assigns the contents (public member function)
swap (C++11)swaps the contents (public member function)

非会员职能

make_paircreates a pair object of type, defined by the argument types (function template)
operator==operator!=operator<operator<=operator>operator>=lexicographically compares the values in the pair (function template)
std::swap(std::pair) (C++11)specializes the std::swap algorithm (function template)
std::get(std::pair) (C++11)accesses an element of a pair (function template)

帮助者类

std::tuple_size (C++11)obtains the size of a pair (class template specialization)
std::tuple_element<std::pair> (C++11)obtains the type of the elements of pair (class template specialization)

另见

tuple (C++11)implements fixed size container, which holds elements of possibly different types (class template)
tiecreates a tuple of lvalue references or unpacks a tuple into individual objects (function template)

© cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

http://en.cppreference.com/w/cpp/实用程序/对