Skip to content

Commit b9d1771

Browse files
committed
Use auto&& for cleaner code
1 parent 3ece9b1 commit b9d1771

File tree

1 file changed

+15
-52
lines changed

1 file changed

+15
-52
lines changed

include/glaze/json/write.hpp

+15-52
Original file line numberDiff line numberDiff line change
@@ -1110,53 +1110,25 @@ namespace glz
11101110
[[maybe_unused]] bool starting = write_first_entry(it);
11111111
++it;
11121112
for (const auto end = std::end(value); it != end; ++it) {
1113-
// I couldn't find an easy way around this code duplication
1114-
// Ranges need to be decomposed with const auto& [...],
1115-
// but we don't want to const qualify our maps for the sake of reflection writing
1116-
// we need to be able to populate the tuple of pointers when writing with reflection
1117-
if constexpr (requires {
1118-
it->first;
1119-
it->second;
1120-
}) {
1121-
if (skip_member<Opts>(it->second)) {
1122-
continue;
1123-
}
1113+
auto&& [key, entry_val] = *it;
1114+
if (skip_member<Opts>(entry_val)) {
1115+
continue;
1116+
}
11241117

1125-
// When Opts.skip_null_members, *any* entry may be skipped, meaning separator dumping must be
1126-
// conditional for every entry. Avoid this branch when not skipping null members.
1127-
// Alternatively, write separator after each entry except last but then branch is permanent
1128-
if constexpr (Opts.skip_null_members) {
1129-
if (!starting) {
1130-
write_object_entry_separator<Opts>(ctx, b, ix);
1131-
}
1132-
}
1133-
else {
1118+
// When Opts.skip_null_members, *any* entry may be skipped, meaning separator dumping must be
1119+
// conditional for every entry. Avoid this branch when not skipping null members.
1120+
// Alternatively, write separator after each entry except last but then branch is permanent
1121+
if constexpr (Opts.skip_null_members) {
1122+
if (!starting) {
11341123
write_object_entry_separator<Opts>(ctx, b, ix);
11351124
}
1136-
1137-
write_pair_content<Opts>(it->first, it->second, ctx, b, ix);
11381125
}
11391126
else {
1140-
const auto& [key, entry_val] = *it;
1141-
if (skip_member<Opts>(entry_val)) {
1142-
continue;
1143-
}
1144-
1145-
// When Opts.skip_null_members, *any* entry may be skipped, meaning separator dumping must be
1146-
// conditional for every entry. Avoid this branch when not skipping null members.
1147-
// Alternatively, write separator after each entry except last but then branch is permanent
1148-
if constexpr (Opts.skip_null_members) {
1149-
if (!starting) {
1150-
write_object_entry_separator<Opts>(ctx, b, ix);
1151-
}
1152-
}
1153-
else {
1154-
write_object_entry_separator<Opts>(ctx, b, ix);
1155-
}
1156-
1157-
write_pair_content<Opts>(key, entry_val, ctx, b, ix);
1127+
write_object_entry_separator<Opts>(ctx, b, ix);
11581128
}
11591129

1130+
write_pair_content<Opts>(key, entry_val, ctx, b, ix);
1131+
11601132
starting = false;
11611133
}
11621134
}
@@ -1178,18 +1150,9 @@ namespace glz
11781150
write_first_entry(it);
11791151
++it;
11801152
for (const auto end = std::end(value); it != end; ++it) {
1181-
if constexpr (requires {
1182-
it->first;
1183-
it->second;
1184-
}) {
1185-
write_object_entry_separator<Opts>(ctx, b, ix);
1186-
write_pair_content<Opts>(it->first, it->second, ctx, b, ix);
1187-
}
1188-
else {
1189-
const auto& [key, entry_val] = *it;
1190-
write_object_entry_separator<Opts>(ctx, b, ix);
1191-
write_pair_content<Opts>(key, entry_val, ctx, b, ix);
1192-
}
1153+
auto&& [key, entry_val] = *it;
1154+
write_object_entry_separator<Opts>(ctx, b, ix);
1155+
write_pair_content<Opts>(key, entry_val, ctx, b, ix);
11931156
}
11941157
}
11951158
}

0 commit comments

Comments
 (0)