-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathtieTuple.cpp
More file actions
33 lines (26 loc) · 870 Bytes
/
tieTuple.cpp
File metadata and controls
33 lines (26 loc) · 870 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// packing/unpacking tuples
#include <iostream>
#include <tuple> // std::tuple, std::make_tuple, std::tie
#include <set>
#include <string>
using namespace std;
int main() {
int myint;
char mychar;
tuple<int, float, char> mytuple;
mytuple = make_tuple(10, 2.6, 'a'); // packing values into tuple
tie(myint, ignore, mychar) = mytuple; // unpacking tuple into variables
cout << "myint contains: " << myint << '\n';
cout << "mychar contains: " << mychar << '\n';
set<string> set_of_str;
bool inserted = false;
set<string>::iterator it;
// insert返回值一个指向插入位置的迭代器和一个布尔值
tie(it, inserted) = set_of_str.insert("Test");
set_of_str.insert("Test1");
cout << *it << endl;
if (inserted) {
cout << "Value was inserted successfully\n";
}
return 0;
}