-
Notifications
You must be signed in to change notification settings - Fork 0
/
type_traits-02.cc
45 lines (38 loc) · 960 Bytes
/
type_traits-02.cc
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
//
// Program
// Type traits - a basic implementation to check
// variable is const qualified or not.
//
// Compile
// g++ -Wall -Wextra -pedantic -std=c++17 -o type_traits-02 type_traits-02.cc
//
// Execution
// ./type_traits-02
//
#include <iostream>
// Define a template-ized structure which
// accepts an element of datatype T
template<typename T>
struct is_const {
// static: To access it without creating object of struct
// const: Once assigned, don't change its value
// value: Recommended variable name to expose value
static const bool value = false;
};
// Specialization of the above template-ized structure
// which takes an element and have true value if given
// element is const qualified.
template<typename T>
struct is_const<const T> {
static const bool value = true;
};
//
// Entry function
//
int main() {
{
static_assert(is_const<const int>::value);
static_assert(not is_const<int>::value);
}
return 0;
}