1// make_pair example
2#include <utility> // std::pair
3#include <iostream> // std::cout
4
5int main () {
6 std::pair <int,int> foo;
7 std::pair <int,int> bar;
8
9 foo = std::make_pair (10,20);
10 bar = std::make_pair (10.5,'A'); // ok: implicit conversion from pair<double,char>
11
12 std::cout << "foo: " << foo.first << ", " << foo.second << '\n';
13 std::cout << "bar: " << bar.first << ", " << bar.second << '\n';
14
15 return 0;
16}
1// pair::pair example
2#include <utility> // std::pair, std::make_pair
3#include <string> // std::string
4#include <iostream> // std::cout
5
6int main () {
7 std::pair <std::string,double> product1; // default constructor
8 std::pair <std::string,double> product2 ("tomatoes",2.30); // value init
9 std::pair <std::string,double> product3 (product2); // copy constructor
10
11 product1 = std::make_pair(std::string("lightbulbs"),0.99); // using make_pair (move)
12 return 0;
13}