Skip to content

Commit 0c2556c

Browse files
committed
chore: update meojson incomplete type fix
1 parent 2472104 commit 0c2556c

4 files changed

Lines changed: 149 additions & 67 deletions

File tree

include/meojson/common/array.hpp

Lines changed: 8 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,7 @@ class array
7979
&& !_utils::has_to_json_in_member<arr_t<value_t, size>>::value
8080
&& !_utils::has_to_json_in_templ_spec<arr_t<value_t, size>>::value,
8181
bool> = true>
82-
array(const arr_t<value_t, size>& arr)
83-
{
84-
_array_data.reserve(size);
85-
for (size_t i = 0; i < size; i++) {
86-
_array_data.emplace_back(arr.at(i));
87-
}
88-
}
82+
array(const arr_t<value_t, size>& arr);
8983

9084
template <
9185
template <typename, size_t> typename arr_t,
@@ -96,13 +90,7 @@ class array
9690
&& !_utils::has_to_json_in_member<arr_t<value_t, size>>::value
9791
&& !_utils::has_to_json_in_templ_spec<arr_t<value_t, size>>::value,
9892
bool> = true>
99-
array(arr_t<value_t, size>&& arr)
100-
{
101-
_array_data.reserve(size);
102-
for (size_t i = 0; i < size; i++) {
103-
_array_data.emplace_back(std::move(arr.at(i)));
104-
}
105-
}
93+
array(arr_t<value_t, size>&& arr);
10694

10795
// Native support for collections (std::vector, std::list, std::set, etc.)
10896
template <
@@ -111,31 +99,15 @@ class array
11199
_utils::is_collection<collection_t> && !std::is_same_v<std::decay_t<collection_t>, array>
112100
&& !_utils::has_to_json_in_member<collection_t>::value && !_utils::has_to_json_in_templ_spec<collection_t>::value,
113101
bool> = true>
114-
array(const collection_t& coll)
115-
{
116-
if constexpr (_utils::has_size<collection_t>::value) {
117-
_array_data.reserve(coll.size());
118-
}
119-
for (const auto& val : coll) {
120-
_array_data.emplace_back(val);
121-
}
122-
}
102+
array(const collection_t& coll);
123103

124104
template <
125105
typename collection_t,
126106
std::enable_if_t<
127107
_utils::is_collection<collection_t> && !std::is_same_v<std::decay_t<collection_t>, array>
128108
&& !_utils::has_to_json_in_member<collection_t>::value && !_utils::has_to_json_in_templ_spec<collection_t>::value,
129109
bool> = true>
130-
array(collection_t&& coll)
131-
{
132-
if constexpr (_utils::has_size<collection_t>::value) {
133-
_array_data.reserve(coll.size());
134-
}
135-
for (auto& val : coll) {
136-
_array_data.emplace_back(std::move(val));
137-
}
138-
}
110+
array(collection_t&& coll);
139111

140112
// Native support for tuple-like types (std::tuple, std::pair)
141113
template <
@@ -146,12 +118,7 @@ class array
146118
&& !_utils::has_to_json_in_member<tuple_t<args_t...>>::value
147119
&& !_utils::has_to_json_in_templ_spec<tuple_t<args_t...>>::value,
148120
bool> = true>
149-
array(const tuple_t<args_t...>& tpl)
150-
{
151-
constexpr size_t tuple_size = std::tuple_size_v<tuple_t<args_t...>>;
152-
_array_data.reserve(tuple_size);
153-
construct_from_tuple_helper(tpl, std::make_index_sequence<tuple_size>());
154-
}
121+
array(const tuple_t<args_t...>& tpl);
155122

156123
template <
157124
template <typename...> typename tuple_t,
@@ -161,12 +128,7 @@ class array
161128
&& !_utils::has_to_json_in_member<tuple_t<args_t...>>::value
162129
&& !_utils::has_to_json_in_templ_spec<tuple_t<args_t...>>::value,
163130
bool> = true>
164-
array(tuple_t<args_t...>&& tpl)
165-
{
166-
constexpr size_t tuple_size = std::tuple_size_v<tuple_t<args_t...>>;
167-
_array_data.reserve(tuple_size);
168-
construct_from_tuple_move_helper(std::move(tpl), std::make_index_sequence<tuple_size>());
169-
}
131+
array(tuple_t<args_t...>&& tpl);
170132

171133
~array() noexcept;
172134

@@ -198,18 +160,10 @@ class array
198160

199161
private:
200162
template <typename tuple_t, size_t... Is>
201-
void construct_from_tuple_helper(const tuple_t& tpl, std::index_sequence<Is...>)
202-
{
203-
using std::get;
204-
(_array_data.emplace_back(get<Is>(tpl)), ...);
205-
}
163+
void construct_from_tuple_helper(const tuple_t& tpl, std::index_sequence<Is...>);
206164

207165
template <typename tuple_t, size_t... Is>
208-
void construct_from_tuple_move_helper(tuple_t&& tpl, std::index_sequence<Is...>)
209-
{
210-
using std::get;
211-
(_array_data.emplace_back(std::move(get<Is>(tpl))), ...);
212-
}
166+
void construct_from_tuple_move_helper(tuple_t&& tpl, std::index_sequence<Is...>);
213167

214168
template <typename tuple_t, size_t... Is>
215169
void as_tuple_helper(tuple_t& result, std::index_sequence<Is...>) const;

include/meojson/common/array_impl.hpp

Lines changed: 111 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,102 @@ inline array::array(typename raw_array::size_type size)
3636
{
3737
}
3838

39+
template <
40+
template <typename, size_t> typename arr_t,
41+
typename value_t,
42+
size_t array_size,
43+
std::enable_if_t<
44+
_utils::is_fixed_array<arr_t<value_t, array_size>> && !std::is_same_v<std::decay_t<arr_t<value_t, array_size>>, array>
45+
&& !_utils::has_to_json_in_member<arr_t<value_t, array_size>>::value
46+
&& !_utils::has_to_json_in_templ_spec<arr_t<value_t, array_size>>::value,
47+
bool>>
48+
inline array::array(const arr_t<value_t, array_size>& arr)
49+
{
50+
_array_data.reserve(array_size);
51+
for (size_t i = 0; i < array_size; i++) {
52+
_array_data.emplace_back(arr.at(i));
53+
}
54+
}
55+
56+
template <
57+
template <typename, size_t> typename arr_t,
58+
typename value_t,
59+
size_t array_size,
60+
std::enable_if_t<
61+
_utils::is_fixed_array<arr_t<value_t, array_size>> && !std::is_same_v<std::decay_t<arr_t<value_t, array_size>>, array>
62+
&& !_utils::has_to_json_in_member<arr_t<value_t, array_size>>::value
63+
&& !_utils::has_to_json_in_templ_spec<arr_t<value_t, array_size>>::value,
64+
bool>>
65+
inline array::array(arr_t<value_t, array_size>&& arr)
66+
{
67+
_array_data.reserve(array_size);
68+
for (size_t i = 0; i < array_size; i++) {
69+
_array_data.emplace_back(std::move(arr.at(i)));
70+
}
71+
}
72+
73+
template <
74+
typename collection_t,
75+
std::enable_if_t<
76+
_utils::is_collection<collection_t> && !std::is_same_v<std::decay_t<collection_t>, array>
77+
&& !_utils::has_to_json_in_member<collection_t>::value && !_utils::has_to_json_in_templ_spec<collection_t>::value,
78+
bool>>
79+
inline array::array(const collection_t& coll)
80+
{
81+
if constexpr (_utils::has_size<collection_t>::value) {
82+
_array_data.reserve(coll.size());
83+
}
84+
for (const auto& val : coll) {
85+
_array_data.emplace_back(val);
86+
}
87+
}
88+
89+
template <
90+
typename collection_t,
91+
std::enable_if_t<
92+
_utils::is_collection<collection_t> && !std::is_same_v<std::decay_t<collection_t>, array>
93+
&& !_utils::has_to_json_in_member<collection_t>::value && !_utils::has_to_json_in_templ_spec<collection_t>::value,
94+
bool>>
95+
inline array::array(collection_t&& coll)
96+
{
97+
if constexpr (_utils::has_size<collection_t>::value) {
98+
_array_data.reserve(coll.size());
99+
}
100+
for (auto& val : coll) {
101+
_array_data.emplace_back(std::move(val));
102+
}
103+
}
104+
105+
template <
106+
template <typename...> typename tuple_t,
107+
typename... args_t,
108+
std::enable_if_t<
109+
_utils::is_tuple_like<tuple_t<args_t...>> && !std::is_same_v<std::decay_t<tuple_t<args_t...>>, array>
110+
&& !_utils::has_to_json_in_member<tuple_t<args_t...>>::value
111+
&& !_utils::has_to_json_in_templ_spec<tuple_t<args_t...>>::value,
112+
bool>>
113+
inline array::array(const tuple_t<args_t...>& tpl)
114+
{
115+
constexpr size_t tuple_size = std::tuple_size_v<tuple_t<args_t...>>;
116+
_array_data.reserve(tuple_size);
117+
construct_from_tuple_helper(tpl, std::make_index_sequence<tuple_size>());
118+
}
119+
120+
template <
121+
template <typename...> typename tuple_t,
122+
typename... args_t,
123+
std::enable_if_t<
124+
_utils::is_tuple_like<tuple_t<args_t...>> && !std::is_same_v<std::decay_t<tuple_t<args_t...>>, array>
125+
&& !_utils::has_to_json_in_member<tuple_t<args_t...>>::value
126+
&& !_utils::has_to_json_in_templ_spec<tuple_t<args_t...>>::value,
127+
bool>>
128+
inline array::array(tuple_t<args_t...>&& tpl)
129+
{
130+
constexpr size_t tuple_size = std::tuple_size_v<tuple_t<args_t...>>;
131+
_array_data.reserve(tuple_size);
132+
construct_from_tuple_move_helper(std::move(tpl), std::make_index_sequence<tuple_size>());
133+
}
134+
39135
inline bool array::empty() const noexcept
40136
{
41137
return _array_data.empty();
@@ -413,7 +509,7 @@ inline T array::as() &&
413509
if (_array_data.size() != tuple_size) {
414510
throw exception("Array size mismatch for tuple conversion: expected=" + std::to_string(tuple_size) + ", actual=" + std::to_string(_array_data.size()));
415511
}
416-
512+
417513
T result;
418514
move_as_tuple_helper(result, std::make_index_sequence<tuple_size>());
419515
_array_data.clear();
@@ -424,6 +520,20 @@ inline T array::as() &&
424520
}
425521
}
426522

523+
template <typename tuple_t, size_t... Is>
524+
inline void array::construct_from_tuple_helper(const tuple_t& tpl, std::index_sequence<Is...>)
525+
{
526+
using std::get;
527+
(_array_data.emplace_back(get<Is>(tpl)), ...);
528+
}
529+
530+
template <typename tuple_t, size_t... Is>
531+
inline void array::construct_from_tuple_move_helper(tuple_t&& tpl, std::index_sequence<Is...>)
532+
{
533+
using std::get;
534+
(_array_data.emplace_back(std::move(get<Is>(tpl))), ...);
535+
}
536+
427537
template <typename tuple_t, size_t... Is>
428538
inline void array::as_tuple_helper(tuple_t& result, std::index_sequence<Is...>) const
429539
{

include/meojson/common/object.hpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,7 @@ class object
7575
&& !std::is_same_v<std::decay_t<map_t>, object> && !_utils::has_to_json_in_member<map_t>::value
7676
&& !_utils::has_to_json_in_templ_spec<map_t>::value,
7777
bool> = true>
78-
object(const map_t& m)
79-
{
80-
for (const auto& [key, val] : m) {
81-
_object_data.emplace(key, val);
82-
}
83-
}
78+
object(const map_t& m);
8479

8580
template <
8681
typename map_t,
@@ -89,12 +84,7 @@ class object
8984
&& !std::is_same_v<std::decay_t<map_t>, object> && !_utils::has_to_json_in_member<map_t>::value
9085
&& !_utils::has_to_json_in_templ_spec<map_t>::value,
9186
bool> = true>
92-
object(map_t&& m)
93-
{
94-
for (auto& [key, val] : m) {
95-
_object_data.emplace(key, std::move(val));
96-
}
97-
}
87+
object(map_t&& m);
9888

9989
~object();
10090

include/meojson/common/object_impl.hpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,34 @@ inline object::object(std::initializer_list<value_type> init_list)
3333
{
3434
}
3535

36+
template <
37+
typename map_t,
38+
std::enable_if_t<
39+
_utils::is_map<map_t> && std::is_same_v<typename map_t::key_type, std::string>
40+
&& !std::is_same_v<std::decay_t<map_t>, object> && !_utils::has_to_json_in_member<map_t>::value
41+
&& !_utils::has_to_json_in_templ_spec<map_t>::value,
42+
bool>>
43+
inline object::object(const map_t& m)
44+
{
45+
for (const auto& [key, val] : m) {
46+
_object_data.emplace(key, val);
47+
}
48+
}
49+
50+
template <
51+
typename map_t,
52+
std::enable_if_t<
53+
_utils::is_map<map_t> && std::is_same_v<typename map_t::key_type, std::string>
54+
&& !std::is_same_v<std::decay_t<map_t>, object> && !_utils::has_to_json_in_member<map_t>::value
55+
&& !_utils::has_to_json_in_templ_spec<map_t>::value,
56+
bool>>
57+
inline object::object(map_t&& m)
58+
{
59+
for (auto& [key, val] : m) {
60+
_object_data.emplace(key, std::move(val));
61+
}
62+
}
63+
3664
inline bool object::contains(const std::string& key) const
3765
{
3866
return _object_data.find(key) != _object_data.cend();

0 commit comments

Comments
 (0)