26
26
#ifndef MARSHALLING_INFERENCE_TYPE_TRAITS_HPP
27
27
#define MARSHALLING_INFERENCE_TYPE_TRAITS_HPP
28
28
29
- #include < type_traits>
30
-
31
29
#include < boost/type_traits.hpp>
32
30
#include < boost/type_traits/is_same.hpp>
33
31
38
36
39
37
namespace nil {
40
38
namespace marshalling {
41
- template <typename T, typename Enabled = void >
42
- struct is_compatible {
43
- static const bool value = false ;
44
- };
45
39
46
40
template <typename T, typename Enabled = void >
47
- struct is_fixed_size {
48
- static const bool value = false ;
49
- };
50
-
51
- template <typename T>
52
- struct is_fixed_size <
53
- T, typename std::enable_if<std::is_integral<T>::value || std::is_floating_point<T>::value>::type> {
54
- static const bool value = true ;
55
- };
56
-
57
- template <typename T>
58
- struct is_fixed_size <std::vector<T>,
59
- typename std::enable_if<is_compatible<T>::value && is_fixed_size<T>::value>::type> {
60
- static const bool value = false ;
61
- };
62
-
63
- template <typename T, std::size_t TSize>
64
- struct is_fixed_size <std::array<T, TSize>,
65
- typename std::enable_if<is_compatible<T>::value && is_fixed_size<T>::value>::type> {
66
- static const bool value = true ;
67
- };
41
+ class is_compatible ;
68
42
69
43
template <typename T>
70
- struct is_compatible <T, typename std::enable_if<std::is_integral<T>::value>::type> {
44
+ class is_compatible <T, typename std::enable_if<std::is_integral<T>::value>::type> {
71
45
using default_endianness = option::big_endian;
72
-
73
- template <typename TEndian = default_endianness>
46
+ public:
47
+ template <typename TEndian = default_endianness>
74
48
using type = typename types::integral<field_type<TEndian>, T>;
75
49
static const bool value = true ;
50
+ static const bool fixed_size = true ;
76
51
};
77
52
78
53
template <typename T>
79
- struct is_compatible <T, typename std::enable_if<std::is_floating_point<T>::value>::type> {
54
+ class is_compatible <T, typename std::enable_if<std::is_floating_point<T>::value>::type> {
80
55
using default_endianness = option::big_endian;
81
-
82
- template <typename TEndian = default_endianness>
56
+ public:
57
+ template <typename TEndian = default_endianness>
83
58
using type = typename types::float_value<field_type<TEndian>, T>;
84
59
static const bool value = true ;
60
+ static const bool fixed_size = true ;
85
61
};
86
62
87
63
template <typename T>
88
- struct is_compatible <std::vector<T>,
89
- typename std::enable_if<is_compatible<T>::value && is_fixed_size <T>::value >::type> {
64
+ class is_compatible <std::vector<T>, typename std::enable_if<is_compatible<T>::value
65
+ && is_compatible <T>::fixed_size >::type> {
90
66
using default_endianness = option::big_endian;
91
-
92
- template <typename TEndian = default_endianness>
93
- using type =
94
- typename types::array_list<field_type<TEndian>, typename is_compatible<T>::template type<TEndian>>;
67
+ public:
68
+ template <typename TEndian = default_endianness>
69
+ using type = typename types::array_list<
70
+ field_type<TEndian>,
71
+ typename is_compatible<T>::template type<TEndian>>;
95
72
static const bool value = true ;
73
+ static const bool fixed_size = false ;
96
74
};
97
75
98
76
template <typename T, std::size_t TSize>
99
- struct is_compatible <std::array<T, TSize>,
100
- typename std::enable_if<is_compatible<T>::value && is_fixed_size <T>::value >::type> {
77
+ class is_compatible <std::array<T, TSize>, typename std::enable_if<is_compatible<T>::value
78
+ && is_compatible <T>::fixed_size >::type> {
101
79
using default_endianness = option::big_endian;
102
-
103
- template <typename TEndian = default_endianness>
104
- using type =
105
- typename types::array_list<field_type<TEndian>, typename is_compatible<T>::template type<TEndian>,
106
- option::fixed_size_storage<TSize>>;
80
+ public:
81
+ template <typename TEndian = default_endianness>
82
+ using type = typename types::array_list<
83
+ field_type<TEndian>,
84
+ typename is_compatible<T>::template type<TEndian>,
85
+ option::fixed_size_storage<TSize>>;
107
86
static const bool value = true ;
87
+ static const bool fixed_size = true ;
108
88
};
109
89
110
90
template <typename T, std::size_t TSize>
111
- struct is_compatible <boost::array<T, TSize>,
112
- typename std::enable_if<is_compatible<T>::value && is_fixed_size <T>::value >::type> {
91
+ class is_compatible <boost::array<T, TSize>, typename std::enable_if<is_compatible<T>::value
92
+ && is_compatible <T>::fixed_size >::type> {
113
93
using default_endianness = option::big_endian;
114
-
115
- template <typename TEndian = default_endianness>
116
- using type =
117
- typename types::array_list<field_type<TEndian>, typename is_compatible<T>::template type<TEndian>,
118
- option::fixed_size_storage<TSize>>;
94
+ public:
95
+ template <typename TEndian = default_endianness>
96
+ using type = typename types::array_list<
97
+ field_type<TEndian>,
98
+ typename is_compatible<T>::template type<TEndian>,
99
+ option::fixed_size_storage<TSize>>;
119
100
static const bool value = true ;
101
+ static const bool fixed_size = true ;
120
102
};
121
103
122
- } // namespace marshalling
104
+ } // namespace marshalling
123
105
} // namespace nil
124
106
125
107
#endif // MARSHALLING_INFERENCE_TYPE_TRAITS_HPP
0 commit comments