-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinspect.h
More file actions
76 lines (58 loc) · 1.79 KB
/
inspect.h
File metadata and controls
76 lines (58 loc) · 1.79 KB
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
//
// Created by Makram Kamaleddine on 10/28/15.
//
#ifndef MY_MPL_INSPECT_H
#define MY_MPL_INSPECT_H
#include <stddef.h>
#include "intops.h"
namespace mpl {
// a metafunction that gets the compile time
// rank of an array
// base case: T is not an array type (i.e its a scalar type)
template<typename T>
struct rank {
enum { value = 0u };
};
// recursion: U could be an array type as well
template<class U, size_t N>
struct rank<U[N]> {
enum { value = 1u + rank<U>::value };
};
// unbounded array type
template<typename U>
struct rank<U[]> {
enum { value = 1u + rank<U>::value };
};
// identity metafunction
template<typename T>
struct type_id {
using type = T;
};
// alias template
// for better usability
template<typename T>
using type_of = typename type_id<T>::type;
// equality of types: really useful!
// false by default
template<typename T, typename U> struct equal_types : false_type { };
// true only if they match
template<typename T> struct equal_types<T, T> : true_type { };
// generalizing equal_types:
// is the given type _one_ of the list of types?
// decl first
template<typename T, typename... types>
struct is_any_of;
// base case 1:
// given list is empty
template<typename T>
struct is_any_of<T> : false_type { };
// base case 2:
// the head of the list is the type we want
template<typename T, typename... types>
struct is_any_of<T, T, types...> : true_type { };
// recursion:
// head is not the type we want: inspect the tail of the list
template<typename T, typename T0, typename... types>
struct is_any_of<T, T0, types...> : is_any_of<T, types...> { };
}
#endif //MY_MPL_INSPECT_H