-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy path2.07.decltype.cpp
More file actions
24 lines (22 loc) · 612 Bytes
/
2.07.decltype.cpp
File metadata and controls
24 lines (22 loc) · 612 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
//
// 2.7.decltype.cpp
// chapter 2 language usability
// modern cpp tutorial
//
// created by changkun at changkun.de
// https://github.com/changkun/modern-cpp-tutorial
//
#include <iostream>
#include <type_traits>
int main() {
auto x = 1;
auto y = 2;
decltype(x+y) z = 3;
if (std::is_same<decltype(x), int>::value)
std::cout << "type x == int" << std::endl;
if (std::is_same<decltype(x), float>::value)
std::cout << "type z == float" << std::endl;
if (std::is_same<decltype(x), decltype(z)>::value)
std::cout << "type z == type x" << std::endl;
return 0;
}