-
Notifications
You must be signed in to change notification settings - Fork 0
/
auto_specification.hpp
42 lines (39 loc) · 1.41 KB
/
auto_specification.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
#pragma once
#include <type_traits>
namespace compile_time {
namespace specification {
template <typename T> struct permitted_raw;
template <typename T>
inline constexpr bool is_permitted_raw =
specification::permitted_raw<T>::value || std::is_arithmetic<T>::value;
} // namespace specification
namespace value {
template <bool, typename> struct default_convert;
template <typename T> struct default_convert<true, T> { using type = T; };
template <typename client> struct instance;
template <typename T> struct default_convert<false, T> {
using type = instance<T>;
};
} // namespace value
namespace types {
template <typename, typename...> struct instance;
template <bool, typename> struct default_convert;
template <typename T> struct default_convert<true, T> { using type = T; };
template <typename T> struct default_convert<false, T> {
template <typename... Fields> using type = instance<T, Fields...>;
};
} // namespace types
namespace specification {
template <typename T>
struct convert_to_instance
: public value::default_convert<is_permitted_raw<T>, T> {};
template <typename T>
struct convert_to_type : public types::default_convert<is_permitted_raw<T>, T> {
};
template <typename T>
struct convert_to_instance<value::instance<T>> : public convert_to_instance<T> {
};
template <typename T>
struct convert_to_type<types::instance<T>> : public convert_to_type<T> {};
} // namespace specification
} // namespace compile_time