13
13
#pragma warning(disable : 4100 4189)
14
14
#endif
15
15
16
- namespace glz ::detail
17
- {
18
- // We create const and not-const versions for when our reflected struct is const or non-const qualified
19
- template <class Tuple >
20
- struct tuple_ptr ;
21
-
22
- template <class ... Ts>
23
- struct tuple_ptr <tuplet::tuple<Ts...>>
24
- {
25
- using type = tuplet::tuple<std::add_pointer_t <std::remove_reference_t <Ts>>...>;
26
- };
27
-
28
- template <class Tuple >
29
- struct tuple_ptr_const ;
30
-
31
- template <class ... Ts>
32
- struct tuple_ptr_const <tuplet::tuple<Ts...>>
33
- {
34
- using type = tuplet::tuple<std::add_pointer_t <std::add_const_t <std::remove_reference_t <Ts>>>...>;
35
- };
36
-
37
- // This is needed to hack a fix for MSVC evaluating wrong `if constexpr` branches
38
- template <class T >
39
- requires (!reflectable<T>)
40
- constexpr auto make_tuple_from_struct () noexcept
41
- {
42
- return glz::tuplet::tuple{};
43
- }
44
-
45
- // This needs to produce const qualified pointers so that we can write out const structs
46
- template <reflectable T>
47
- constexpr auto make_tuple_from_struct () noexcept
48
- {
49
- using V = decay_keep_volatile_t <decltype (to_tuple (std::declval<T>()))>;
50
- return typename tuple_ptr<V>::type{};
51
- }
52
-
53
- template <reflectable T>
54
- constexpr auto make_const_tuple_from_struct () noexcept
55
- {
56
- using V = decay_keep_volatile_t <decltype (to_tuple (std::declval<T>()))>;
57
- return typename tuple_ptr_const<V>::type{};
58
- }
59
-
60
- template <reflectable T, class TuplePtrs >
61
- requires (!std::is_const_v<TuplePtrs>)
62
- constexpr void populate_tuple_ptr (T&& value, TuplePtrs& tuple_of_ptrs) noexcept
63
- {
64
- // we have to populate the pointers in the reflection tuple from the structured binding
65
- auto t = to_tuple (std::forward<T>(value));
66
- [&]<size_t ... I>(std::index_sequence<I...>) {
67
- ((get<I>(tuple_of_ptrs) = &get<I>(t)), ...);
68
- }(std::make_index_sequence<count_members<T>>{});
69
- }
70
- }
71
-
72
16
namespace glz
73
17
{
74
18
// Get indices of elements satisfying a predicate
@@ -246,8 +190,6 @@ namespace glz
246
190
using V = std::remove_cvref_t <T>;
247
191
using tuple = decay_keep_volatile_t <decltype(to_tuple(std::declval<T>()))>;
248
192
249
- // static constexpr auto values = typename detail::tuple_ptr<tuple>::type{};
250
-
251
193
static constexpr auto keys = member_names<V>;
252
194
static constexpr auto size = keys.size();
253
195
@@ -528,15 +470,6 @@ namespace glz::detail
528
470
constexpr auto indices = std::make_index_sequence<reflect<T>::size>{};
529
471
return make_map_impl<decay_keep_volatile_t <T>, use_hash_comparison>(indices);
530
472
}
531
-
532
- template <class T >
533
- constexpr auto make_key_int_map ()
534
- {
535
- constexpr auto N = reflect<T>::size;
536
- return [&]<size_t ... I>(std::index_sequence<I...>) {
537
- return normal_map<sv, size_t , reflect<T>::size>(pair<sv, size_t >{reflect<T>::keys[I], I}...);
538
- }(std::make_index_sequence<N>{});
539
- }
540
473
}
541
474
542
475
namespace glz
@@ -705,18 +638,6 @@ namespace glz
705
638
constexpr auto indices = std::make_index_sequence<count_members<T>>{};
706
639
return make_reflection_map_impl<decay_keep_volatile_t <T>, use_hash_comparison>(indices);
707
640
}
708
-
709
- template <reflectable T>
710
- GLZ_ALWAYS_INLINE constexpr void populate_map (T&& value, auto & cmap) noexcept
711
- {
712
- // we have to populate the pointers in the reflection map from the structured binding
713
- auto t = to_tuple (std::forward<T>(value));
714
- [&]<size_t ... I>(std::index_sequence<I...>) {
715
- ((get<std::add_pointer_t <decay_keep_volatile_t <decltype (get<I>(t))>>>(get<I>(cmap.items ).second ) =
716
- &get<I>(t)),
717
- ...);
718
- }(std::make_index_sequence<count_members<T>>{});
719
- }
720
641
}
721
642
}
722
643
@@ -785,7 +706,12 @@ namespace glz::detail
785
706
using V = decay_keep_volatile_t <std::variant_alternative_t <I, T>>;
786
707
if constexpr (glaze_object_t <V> || reflectable<V> || is_memory_object<V>) {
787
708
using X = std::conditional_t <is_memory_object<V>, memory_type<V>, V>;
788
- for_each<reflect<X>::size>([&](auto J) { deduction_map.find (reflect<X>::keys[J])->second [I] = true ; });
709
+ constexpr auto Size = reflect<X>::size;
710
+ if constexpr (Size > 0 ) {
711
+ for (size_t J = 0 ; J < Size ; ++J) {
712
+ deduction_map.find (reflect<X>::keys[J])->second [I] = true ;
713
+ }
714
+ }
789
715
}
790
716
});
791
717
@@ -795,6 +721,18 @@ namespace glz::detail
795
721
796
722
namespace glz ::detail
797
723
{
724
+ template <class T >
725
+ consteval size_t key_index (const std::string_view key)
726
+ {
727
+ const auto n = reflect<T>::keys.size ();
728
+ for (size_t i = 0 ; i < n; ++i) {
729
+ if (key == reflect<T>::keys[i]) {
730
+ return i;
731
+ }
732
+ }
733
+ return n;
734
+ }
735
+
798
736
GLZ_ALWAYS_INLINE constexpr uint64_t bitmix (uint64_t h, const uint64_t seed) noexcept
799
737
{
800
738
h *= seed;
@@ -851,7 +789,10 @@ namespace glz::detail
851
789
return {};
852
790
}
853
791
792
+ // This could be a std::array, but each length N for std::array causes unique template instaniations
793
+ // This propagates to std::ranges::sort, so using std::vector means less template instaniations
854
794
std::vector<std::string_view> strings{};
795
+ strings.reserve (N);
855
796
for (size_t i = 0 ; i < N; ++i) {
856
797
strings.emplace_back (input_strings[i]);
857
798
}
@@ -1262,7 +1203,7 @@ namespace glz::detail
1262
1203
break ;
1263
1204
}
1264
1205
const auto bucket = hash % bsize;
1265
- if (contains (std::span{ bucket_index.data (), index } , bucket)) {
1206
+ if (contains (bucket_index.data (), index , bucket)) {
1266
1207
break ;
1267
1208
}
1268
1209
bucket_index[index ] = bucket;
@@ -1272,7 +1213,7 @@ namespace glz::detail
1272
1213
if (index == N) {
1273
1214
// make sure the seed does not collide with any hashes
1274
1215
const auto bucket = seed % bsize;
1275
- if (not contains (std::span{ bucket_index.data (), N} , bucket)) {
1216
+ if (not contains (bucket_index.data (), N, bucket)) {
1276
1217
return ; // found working seed
1277
1218
}
1278
1219
}
@@ -1421,7 +1362,7 @@ namespace glz::detail
1421
1362
break ;
1422
1363
}
1423
1364
const auto bucket = hash % bsize;
1424
- if (contains (std::span{ bucket_index.data (), index } , bucket)) {
1365
+ if (contains (bucket_index.data (), index , bucket)) {
1425
1366
break ;
1426
1367
}
1427
1368
bucket_index[index ] = bucket;
@@ -1431,7 +1372,7 @@ namespace glz::detail
1431
1372
if (index == N) {
1432
1373
// make sure the seed does not collide with any hashes
1433
1374
const auto bucket = seed % bsize;
1434
- if (not contains (std::span{ bucket_index.data (), N} , bucket)) {
1375
+ if (not contains (bucket_index.data (), N, bucket)) {
1435
1376
return ; // found working seed
1436
1377
}
1437
1378
}
@@ -1466,7 +1407,7 @@ namespace glz::detail
1466
1407
break ;
1467
1408
}
1468
1409
const auto bucket = hash % bsize;
1469
- if (contains (std::span{ bucket_index.data (), index } , bucket)) {
1410
+ if (contains (bucket_index.data (), index , bucket)) {
1470
1411
break ;
1471
1412
}
1472
1413
bucket_index[index ] = bucket;
@@ -1476,7 +1417,7 @@ namespace glz::detail
1476
1417
if (index == N) {
1477
1418
// make sure the seed does not collide with any hashes
1478
1419
const auto bucket = seed % bsize;
1479
- if (not contains (std::span{ bucket_index.data (), N} , bucket)) {
1420
+ if (not contains (bucket_index.data (), N, bucket)) {
1480
1421
return ; // found working seed
1481
1422
}
1482
1423
}
@@ -1508,7 +1449,7 @@ namespace glz::detail
1508
1449
break ;
1509
1450
}
1510
1451
const auto bucket = hash % bsize;
1511
- if (contains (std::span{ bucket_index.data (), index } , bucket)) {
1452
+ if (contains (bucket_index.data (), index , bucket)) {
1512
1453
break ;
1513
1454
}
1514
1455
bucket_index[index ] = bucket;
@@ -1518,7 +1459,7 @@ namespace glz::detail
1518
1459
if (index == N) {
1519
1460
// make sure the seed does not collide with any hashes
1520
1461
const auto bucket = seed % bsize;
1521
- if (not contains (std::span{ bucket_index.data (), N} , bucket)) {
1462
+ if (not contains (bucket_index.data (), N, bucket)) {
1522
1463
return ; // found working seed
1523
1464
}
1524
1465
}
@@ -1542,7 +1483,7 @@ namespace glz::detail
1542
1483
1543
1484
template <class T >
1544
1485
constexpr auto hash_info = [] {
1545
- if constexpr ((glaze_object_t <T> || reflectable<T> ||
1486
+ if constexpr ((glaze_object_t <T> || reflectable<T> || glaze_flags_t <T> ||
1546
1487
((std::is_enum_v<std::remove_cvref_t <T>> && meta_keys<T>) || glaze_enum_t <T>)) &&
1547
1488
(reflect<T>::size > 0 )) {
1548
1489
constexpr auto & k_info = keys_info<T>;
0 commit comments