-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathIfThenElse2.cpp
More file actions
39 lines (31 loc) · 807 Bytes
/
IfThenElse2.cpp
File metadata and controls
39 lines (31 loc) · 807 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
/*
* HOME : ecourse.co.kr
* EMAIL : smkang @ codenuri.co.kr
* COURSENAME : C++ Template Programming
* MODULE : IfThenElse2.cpp
* Copyright (C) 2017 CODENURI Inc. All rights reserved.
*/
#include <iostream>
using namespace std;
// bool 기반의 type selection 기술.
template<bool, typename T, typename U> struct IfThenElse
{
typedef T type;
};
template<typename T, typename U> struct IfThenElse<false, T, U>
{
typedef U type;
};
template<int N> struct Bit
{
// using data_type = unsigned int;
using data_type = typename IfThenElse< (N <= 8), char, unsigned int>::type;
data_type data;
};
int main()
{
Bit<8> b1; // 8bit를 관리하기 위한 객체
Bit<32> b2; // 32bit를 관리하기 위한 객체
cout << sizeof(b1) << endl;
cout << sizeof(b2) << endl;
}