-
Notifications
You must be signed in to change notification settings - Fork 1
/
TypeIndex.h
41 lines (24 loc) · 962 Bytes
/
TypeIndex.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
#pragma once
#include <Value/Value.h>
#include <boost/mpl/at.hpp>
#include <boost/mpl/int.hpp>
#include <boost/mpl/size.hpp>
namespace Value {
template<typename Type> constexpr int TypeIndex = -1;
template<> constexpr int TypeIndex<Int> = 0;
template<> constexpr int TypeIndex<String> = 1;
template<> constexpr int TypeIndex<Vector> = 2;
template<> constexpr int TypeIndex<Map> = 3;
constexpr int ValueTypeSize = boost::mpl::size<Value::types>::value;
namespace {
template<typename Type, int Index>
using ValueHasTypeAtIndex = std::is_same<
typename boost::mpl::at<Value::types, boost::mpl::int_<Index>>::type,
Type
>;
static_assert(ValueHasTypeAtIndex<Int, TypeIndex<Int>> ::value);
static_assert(ValueHasTypeAtIndex<String, TypeIndex<String>>::value);
static_assert(ValueHasTypeAtIndex<Vector, TypeIndex<Vector>>::value);
static_assert(ValueHasTypeAtIndex<Map, TypeIndex<Map>> ::value);
} // namespace
} // namespace Value