c++ make_pair

创建日期: 2024-07-01 15:20 | 作者: 风波 | 浏览次数: 16 | 分类: C++

文档:https://en.cppreference.com/w/cpp/utility/pair/make_pair

#include <functional>
#include <iostream>
#include <utility>

int main()
{
    int n = 1;
    int a[5] = {1, 2, 3, 4, 5};

    // build a pair from two ints
    auto p1 = std::make_pair(n, a[1]);
    std::cout << "The value of p1 is "
              << '(' << p1.first << ", " << p1.second << ")\n";

    // build a pair from a reference to int and an array (decayed to pointer)
    auto p2 = std::make_pair(std::ref(n), a);
    n = 7;
    std::cout << "The value of p2 is "
              << '(' << p2.first << ", " << *(p2.second + 2) << ")\n";
}
16 浏览
15 爬虫
0 评论