-
Notifications
You must be signed in to change notification settings - Fork 0
/
meta.h
53 lines (45 loc) · 1.67 KB
/
meta.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
/***************************************************************************
meta.h - description
-------------------
begin : Sat Apr 26 2003
copyright : (C) 2003 by Blake Madden
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the BSD License. *
* *
***************************************************************************/
#ifndef __COMPILE_TIME_META_H__
#define __COMPILE_TIME_META_H__
#include <cwchar>
//converts constants to unsigned/unsigned char or wchar_t at compile time.
template<typename T, T N>
class __character
{
public:
static const T val = (N < 128) ? N : (N - 256);
};
//specialized for signed char
template<char N>
class __character<char, N>
{
public:
static const char val = (N < 128) ? N : static_cast<char>((N - 256));
};
//specialized for unsigned char
template<unsigned char N>
class __character<unsigned char, N>
{
public:
static const unsigned char val = (N < 256) ? N : 255;
};
//specialized for wchar_t
template<wchar_t N>
class __character<wchar_t, N>
{
public:
static const wchar_t val = N;
};
#define assign_character(t, n) __character<t, n>::val
#endif //__COMPILE_TIME_META_H__