-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathTraits.h
38 lines (33 loc) · 879 Bytes
/
Traits.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
/*
*
* Traits to compile time template calculating
*
* @author Valeriy V Dmitriev aka valmat <[email protected]>, http://valmat.ru/
* @licenses MIT https://opensource.org/licenses/MIT
* @repo https://github.com/valmat/LedMatrix
*
*/
// SumTrait is a trait to compile time calculate total cascade size
template <int N0, int ...Ns>
struct SumTrait
{
constexpr static int sum = SumTrait<N0>::sum + SumTrait<Ns...>::sum;
};
template <int N>
struct SumTrait<N>
{
constexpr static int sum = N;
};
// SizeTrait is a trait to compile time calculate template integer argument
template <typename T>
struct SizeTrait;
template < template<int M> class T, int N>
struct SizeTrait< T<N> >
{
constexpr static int size = N;
};
template <typename T>
struct SizeTrait
{
constexpr static int size = SizeTrait< typename std::remove_reference<T>::type >::size;
};