-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtmp_assert.h
79 lines (70 loc) · 1.73 KB
/
tmp_assert.h
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
* tmp_assert.h
*
* Error checking code
*/
#ifndef TMP_ASSERT_H
#define TMP_ASSERT_H
// TMP_Error <typename>
//
// Will create a compile error if the result value within a
// struct gets set to this value
//
template <typename T>
struct TMP_Error {
// Do not set this value - it is for terminating
// faulty code that does not meet the function
// contracts for the following TMP functions~
static const T result;
};
// TMP_Assert...
//
// Each of the following will check an assertion
// and make a compile error something is wrong.
//
// the following are examples of their use:
//
// // returns 1 because 1 <= 2
// TMP_AssertLessThanOrEqualTo <unsigned int, 1, 2>::result;
//
// // returns creates an error during compile because -4
// // is not greater than 7
// TMP_AssertGreater <int, -4, 7>::result;
//
template <typename T, T N, T Compare>
struct TMP_AssertEqualTo
{
static const T result =
N == Compare ? N : TMP_Error<T>::result;
};
template <typename T, T N, T Compare>
struct TMP_AssertNotEqualTo
{
static const T result =
N != Compare ? N : TMP_Error<T>::result;
};
template <typename T, T N, T Compare>
struct TMP_AssertLessThan
{
static const T result =
N < Compare ? N : TMP_Error<T>::result;
};
template <typename T, T N, T Compare>
struct TMP_AssertLessThanOrEqualTo
{
static const T result =
N <= Compare ? N : TMP_Error<T>::result;
};
template <typename T, T N, T Compare>
struct TMP_AssertGreater
{
static const T result =
N > Compare ? N : TMP_Error<T>::result;
};
template <typename T, T N, T Compare>
struct TMP_AssertGreaterOrEqualTo
{
static const T result =
N > Compare ? N : TMP_Error<T>::result;
};
#endif