-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.hpp
72 lines (60 loc) · 2.03 KB
/
types.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
70
71
72
#pragma once
#include "auto_specification.hpp"
#include "specification.hpp"
#include "utils.hpp"
namespace compile_time {
namespace specification {
template <typename T> struct convert_to_type;
}
namespace types {
template <typename... T> struct list {
constexpr list() = default;
template <typename... U>
static constexpr list<T..., U...> append(const list<U...> &) {
return list<T..., U...>{};
}
};
template <char...> struct string { constexpr string() = default; };
template <typename T, typename... Fields> struct instance {
static_assert(sizeof...(Fields) == struct_size<T>,
"Error: incorrect number of fields");
constexpr instance() = default;
static const constexpr bool all_ok{true};
static const constexpr bool is_error{false};
};
struct null_type {
constexpr null_type() = default;
};
// template<typename T> struct default_convert<false, list<T> >
// {template<typename... Fields> using type = instance<T, Fields...>;};
template <typename T, T> struct raw_value { constexpr raw_value() = default; };
template <char... str> struct error {
static constexpr const char msg[sizeof...(str) + 1] = {str..., 0};
static const constexpr bool is_error{true};
};
template <char... str> constexpr bool is_error(const error<str...> &) {
return true;
}
template <typename T> constexpr bool is_error(T &&) { return false; }
template <char... str>
std::ostream &operator<<(std::ostream &o, const error<str...> &e) {
return o << e.msg;
}
template <char... c>
constexpr auto error_from_ctstring(const mutils::String<c...> &) {
return error<c...>{};
}
template <typename FV> constexpr auto error_from_value_error_f() {
struct i {
constexpr i() = default;
constexpr const char *operator()() const { return FV{}().msg; }
};
return error_from_ctstring(mutils::cstring::build_type_string<i>());
}
template <typename T>
using error_from_value_error = DECT(error_from_value_error_f<T>());
template <typename T> struct wrapped_type {
constexpr wrapped_type() = default;
};
} // namespace types
} // namespace compile_time