-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStructuredBindingsRef.cpp
52 lines (39 loc) · 1.08 KB
/
StructuredBindingsRef.cpp
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
* \file StructuredBindingsRef.cpp
* \brief
*/
#include <StdStream/StdStream.h>
#include <StdTest/StdTest.h>
#include <Stl.h>
//--------------------------------------------------------------------------------------------------
struct Point
{
int x;
int y;
};
//--------------------------------------------------------------------------------------------------
int main(int, char **)
{
Point p {1, 2};
// Structure binding
auto &[x_coord, y_coord] = p;
// std::cout << "type: " << typeid( decltype([x_coord, y_coord]) ).name() << std::endl;
std::cout << STD_TRACE_VAR(x_coord) << std::endl;
std::cout << STD_TRACE_VAR(y_coord) << std::endl;
x_coord = 7;
y_coord = 8;
std::cout << STD_TRACE_VAR(x_coord) << std::endl;
std::cout << STD_TRACE_VAR(y_coord) << std::endl;
std::cout << STD_TRACE_VAR(p.x) << std::endl;
std::cout << STD_TRACE_VAR(p.y) << std::endl;
return EXIT_SUCCESS;
}
//-------------------------------------------------------------------------------------------------
#if OUTPUT
x_coord: 1
y_coord: 2
x_coord: 7
y_coord: 8
p.x: 7
p.y: 8
#endif