-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathint2type3.cpp
More file actions
40 lines (32 loc) · 821 Bytes
/
int2type3.cpp
File metadata and controls
40 lines (32 loc) · 821 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
34
35
36
37
38
39
40
/*
* HOME : ecourse.co.kr
* EMAIL : smkang @ codenuri.co.kr
* COURSENAME : C++ Template Programming
* MODULE : int2type3.cpp
* Copyright (C) 2017 CODENURI Inc. All rights reserved.
*/
#include <iostream>
#include <type_traits>
using namespace std;
template<typename T> struct IsPointer { static constexpr bool value = false; };
template<typename T> struct IsPointer<T*> { static constexpr bool value = true; };
template<typename T> void printv(T a)
{
if (IsPointer<T>::value )
cout << a << " : " << *a << endl;
else
cout << a << endl;
// C++17 À» »ç¿ëÇß´Ù¸é ÇØ°áµÊ.
/*
if constexpr (IsPointer<T>::value)
cout << a << " : " << *a << endl;
else
cout << a << endl;
*/
}
int main()
{
int n = 3;
printv(n); // error
printv(&n); // ok.
}