-
Notifications
You must be signed in to change notification settings - Fork 0
/
cxxloop_prereqs.h
118 lines (92 loc) · 4.9 KB
/
cxxloop_prereqs.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#pragma once
#ifdef __cpp_has_cpploop
///////////////////////////////////////////////////////////////////////////
//////////// PRE-requisites /////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
#if !defined __cplusplus
#error("the compound group LOOP will not work with C99 or later")
#endif
// cpp-macro to generate an unique ID
#ifndef CPPMACRO_UNIQUE_ID
#define CPPMACRO_XCAT2(a, b) a##b
#define CPPMACRO_UNIQUE_ID(counter) CPPMACRO_XCAT2(UNIQUE_ID_LOOP_, counter)
#endif
/////////////////////////////////////////////////////////////////////77
// cpp macro to use type of varname and remove const
#include <type_traits>
namespace ogis {
// strip off any of const, volatile or references (T&, T&&)
/*template<typename Type>
using remove_cvref = typename std::remove_reference<\
typename std::remove_const<Type>::type>::type;
*/
template <typename Type>
using remove_cvref_t =
typename std::remove_cv<typename std::remove_reference<Type>::type>::type;
template <typename BaseType, typename TgtType>
using copy_unsigendness_conditional_t =
typename std::conditional<std::is_unsigned<BaseType>::value,
typename std::make_unsigned<TgtType>::type,
TgtType>::type;
template <typename BaseType>
using copy_unsigendness_to_char_t =
copy_unsigendness_conditional_t<BaseType, char>;
template <typename BaseType>
using copy_unsigendness_to_short_t =
copy_unsigendness_conditional_t<BaseType, short>;
} // namespace ogis
// //:CPPMACRO_NTIMES_*
// //:CPPMACRO_NTIMES_[UP|DOWN|FASTEST]
// cpp-macro to count upwards (from 0 to nbrOfRepetitions-1)
#define CPPMACRO_NTIMES_UP(indexType, nbrOfRepetitions, indexVarName) \
for (indexType indexVarName = static_cast<indexType>(0); \
indexVarName < nbrOfRepetitions; indexVarName++)
// cpp-macro to count downwards (from nbrOfRepetitions-1 to 0)
#define CPPMACRO_NTIMES_DOWN(indexType, nbrOfRepetitions, indexVarName) \
for (indexType indexVarName = static_cast<indexType>(nbrOfRepetitions); \
indexVarName-- > 0;)
#define CPPMACRO_NTIMES_FASTEST(indexType, nbrOfRepetitions, indexVarName) \
for (indexType indexVarName = static_cast<indexType>(nbrOfRepetitions); \
indexVarName-- > 0;)
//////////////////////////////
// //:CPPMACRO_LOOP[_TYPED]_POSTOPS
#define CPPMACRO_LOOP(direction, nbrOfRepetitions, indexVarName) \
CPPMACRO_NTIMES_##direction( \
typename ogis::remove_cvref_t<decltype((nbrOfRepetitions))>, \
nbrOfRepetitions, indexVarName)
#define CPPMACRO_LOOP_TYPED(direction, nbrOfRepetitions, indexVarName, type) \
CPPMACRO_NTIMES_##direction( \
ogis::copy_unsigendness_to_##type##_t< \
typename ogis::remove_cvref_t<decltype((nbrOfRepetitions))>>, \
nbrOfRepetitions, indexVarName)
//////// POSTOPS
//////////////////////////////
#ifdef __cpp_has_cpploop_postops
// //:CPPMACRO_NTIMES_[UP|DOWN|FASTEST]_POSTOPS
// cpp-macro to count upwards (from 0 to nbrOfRepetitions-1)
#define CPPMACRO_NTIMES_UP_POSTOPS(indexType, nbrOfRepetitions, indexVarName, \
...) \
for (indexType indexVarName = static_cast<indexType>(0); \
indexVarName < nbrOfRepetitions; indexVarName++, __VA_ARGS__)
// cpp-macro to count downwards (from nbrOfRepetitions-1 to 0)
#define CPPMACRO_NTIMES_DOWN_POSTOPS(indexType, nbrOfRepetitions, \
indexVarName, ...) \
for (indexType indexVarName = static_cast<indexType>(nbrOfRepetitions); \
indexVarName-- > 0; __VA_ARGS__)
#define CPPMACRO_NTIMES_FASTEST_POSTOPS(indexType, nbrOfRepetitions, \
indexVarName, ...) \
for (indexType indexVarName = static_cast<indexType>(nbrOfRepetitions); \
indexVarName-- > 0; __VA_ARGS__)
// //:CPPMACRO_LOOP[_TYPED]_POSTOPS
#define CPPMACRO_LOOP_POSTOPS(direction, nbrOfRepetitions, indexVarName, ...) \
CPPMACRO_NTIMES_##direction##_POSTOPS( \
typename ogis::remove_cvref_t<decltype((nbrOfRepetitions))>, \
nbrOfRepetitions, indexVarName, __VA_ARGS__)
#define CPPMACRO_LOOP_TYPED_POSTOPS(direction, nbrOfRepetitions, indexVarName, \
type, ...) \
CPPMACRO_NTIMES_##direction##_POSTOPS( \
ogis::copy_unsigendness_to_##type##_t< \
typename ogis::remove_cvref_t<decltype((nbrOfRepetitions))>>, \
nbrOfRepetitions, indexVarName, __VA_ARGS__)
#endif
#endif