/
to_type.hpp
69 lines (59 loc) · 1.31 KB
/
to_type.hpp
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
// Copyright (c) Steinwurf ApS 2016.
// All Rights Reserved
//
// Distributed under the "BSD License". See the accompanying LICENSE.rst file.
#pragma once
#include <cstdint>
#include <type_traits>
#include "types.hpp"
namespace bitter
{
namespace detail
{
/// Base case for BitterTypes (see types.hpp)
template<class BitterType>
struct to_type
{
static_assert(BitterType::size > 0, "DataType must have size.");
static_assert(std::is_unsigned<typename BitterType::type>::value,
"DataType must have a nested type which is unsigned. "
"See types.hpp");
using type = BitterType;
};
/// Special case for integer types
template<>
struct to_type<uint8_t>
{
using type = u8;
};
template<>
struct to_type<uint16_t>
{
using type = u16;
};
template<>
struct to_type<uint32_t>
{
using type = u32;
};
template<>
struct to_type<uint64_t>
{
using type = u64;
};
}
/// Helper function that converts a Type to a BitterType which is
/// defined in types.hpp
///
/// If the Type is a BitterType the function is just the identity
/// i.e.:
///
/// bitter::to_type<bitter::u8> == bitter::u8
///
/// However, for other integer types such as uint8_t we have:
///
/// bitter::to_type<uint8_t> == bitter::u8
///
template<class Type>
using to_type = typename detail::to_type<Type>::type;
}