http://www.cplusplus.com/reference/utility/pair/

用于存储一对异构对象

// Compile: g++ -std=c++11 pair.cpp

#include <utility>
#include <string>
#include <iostream>
#include <tuple> int main () {
std::pair <std::string, int> p1; // default constructor
p1 = std::make_pair(std::string("alpha"), ); // using make_pair (move)
std::pair <std::string, int> p2 ("beta", 2.01); // value init
std::pair <std::string, int> p3 (p2); // copy constructor
std::pair <std::string, int> p4 = p2; // assignment operator
std::pair <std::string, int> p5(std::piecewise_construct,
std::forward_as_tuple("omega"),
std::forward_as_tuple()); // c++11, piecewise constructor p2.first = "gamma";
p2.second = 'c'; p1.swap(p4); // c++11
std::swap(p2, p3); // c++11
std::get<>(p1) = "delta"; // c++11, get<0> means first
std::get<>(p1) = 4L; // c++11, get<1> means second std::cout << "p1: (" << p1.first << ", " << p1.second << ")\n";
std::cout << "p2: (" << p2.first << ", " << p2.second << ")\n";
std::cout << "p3: (" << p3.first << ", " << p3.second << ")\n";
std::cout << "p4: (" << std::get<>(p4) << ", " << std::get<>(p4) << ")\n";
std::cout << "p5: (" << std::get<>(p5) << ", " << std::get<>(p5) << ")\n"; return ;
}

cplusplus系列>utility>pair的更多相关文章

  1. cplusplus系列>algorithm>std::for_each

    http://www.cplusplus.com/reference/algorithm/for_each/ 对一个序列应用函数.可以是函数指针,或者是functor. // for_each exa ...

  2. Spark RDD概念学习系列之Pair RDD的分区控制

    不多说,直接上干货! Pair RDD的分区控制 Pair RDD的分区控制 (1) Spark 中所有的键值对RDD 都可以进行分区控制---自定义分区 (2)自定义分区的好处:  1) 避免数据倾 ...

  3. Spark RDD概念学习系列之Pair RDD的action操作

    不多说,直接上干货! Pair RDD的action操作 所有基础RDD 支持的行动操作也都在pair RDD 上可用

  4. Spark RDD概念学习系列之Pair RDD的transformation操作

    不多说,直接上干货! Pair RDD的transformation操作 Pair RDD转换操作1 Pair RDD 可以使用所有标准RDD 上转化操作,还提供了特有的转换操作. Pair RDD转 ...

  5. STL的pair学习, map学习

    http://blog.csdn.net/calvin_zcx/article/details/6072286 http://www.linuxidc.com/Linux/2014-10/107621 ...

  6. lambda、pair、智能指针及时间函数

    Lambda 表达式 auto f1 = [](int x, int y) { return x + y; };cout << f1(2, 3) << endl; int n ...

  7. pair练习

    /* 编写程序读入一些列string和int型数据,将每一组存储在一个pair对象中, 然后将这些pair对象存储在vector容器里. */ #include <iostream> #i ...

  8. C++ Primer 学习笔记_34_STL实践与分析(8) --引言、pair类型、关联容器

    STL实践与分析 --引言.pair类型.关联容器 引言:     关联容器与顺序容器的本质差别在于:关联容器通过键[key]来存储和读取元素,而顺序容器则通过元素在容器中的位置顺序的存取元素. ma ...

  9. 五一 DAY 6

    五一  DAY 6 TypeName   类型名 VariableName  变量名 Part 1 数据结构 函数库:# include < utility > Pair 定义一个变量,它 ...

随机推荐

  1. 【BZOJ3238】差异(后缀数组,单调栈)

    题意: 思路:显然len(t[i])+len(t[j])这部分的和是一定的 那么问题就在于如何快速求出两两之间lcp之和 考虑将它们排名后用SA可以很方便的求出lcp,且对答案没有影响,因为形式都是数 ...

  2. 为 Windows Phone 8.1 app 解决“The type does not support direct content.”的问题

    我在 VS 14 CTP 中新建了一个空的 app store 项目名叫 PlayWithXaml ,项目的 MainPage.xaml 文件改为了以下内容: <Page x:Class=&qu ...

  3. Switch Game

    Problem Description There are many lamps in a line. All of them are off at first. A series of operat ...

  4. resin4开启jmx

    https://blog.csdn.net/liuxiao723846/article/details/51321010 https://blog.csdn.net/u010342008/articl ...

  5. [bzoj2657][Zjoi2012]旅游 journey_ 对偶图_树形dp

    旅游 bzoj-2657 Zjoi-2012 题目大意:题目链接 注释:$1\le K\le 2\cdot 10^5$. 想法:这题... 感觉和上一个题的提示有些类似,就是题目生怕你不知道这是一道对 ...

  6. JavaScript实现页面无刷新让时间走动

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  7. CN Internet

    来自为知笔记(Wiz)

  8. ROBODK仿真如何设置运动速度

    设置工具-选项-运动,把仿真时间设置成跟正常一样   然后双击机器人,设置参数(可以设置movej和movel的速度,加速度)  

  9. Android利用Volley异步载入数据完整具体演示样例(二)

    MainActivity例如以下: package cc.y; import android.app.Activity; import android.content.Context; import ...

  10. cocos2d-x-3.1 数据结构之Vector (coco2d-x 学习笔记六)

    介绍 cocos2d::Vector<T>是一个封装好的能动态增长顺序訪问的容器. cocos2d::Vector<T>中的元素是按序存取的,它的低层实现数据结构是标准模版库中 ...