Skip to content

Commit 90b6358

Browse files
committed
Update for unibrow operator and add one unit test
1 parent 201c530 commit 90b6358

File tree

7 files changed

+33
-20
lines changed

7 files changed

+33
-20
lines changed

benchmarks/simpleparser/from_json.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void from_json(const JsonValue& j, T& obj) requires(simdjson::json_builder::User
4545
}
4646

4747
// Using reflection to iterate over data members
48-
[:simdjson::json_builder::expand(std::meta::nonstatic_data_members_of(^T)):] >> [&]<auto dm> {
48+
[:simdjson::json_builder::expand(std::meta::nonstatic_data_members_of(^^T)):] >> [&]<auto dm> {
4949
constexpr auto name = std::meta::identifier_of(dm);
5050
auto it = j.object_value.find(std::string(reinterpret_cast<const char*>(name.data()), name.size()));
5151
if (it != j.object_value.end()) {

include/simdjson/json_builder/json_builder.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ template <typename R> consteval auto expand(R range) {
4848
for (auto r : range) {
4949
args.push_back(std::meta::reflect_value(r));
5050
}
51-
return substitute(^__impl::replicator, args);
51+
return substitute(^^__impl::replicator, args);
5252
}
5353
// end of workaround
5454

@@ -88,7 +88,7 @@ template <class T>
8888
constexpr void atom(string_builder &b, const T &t) {
8989
int i = 0;
9090
b.append('{');
91-
[:expand(std::meta::nonstatic_data_members_of(^T)):] >> [&]<auto dm> {
91+
[:expand(std::meta::nonstatic_data_members_of(^^T)):] >> [&]<auto dm> {
9292
if (i != 0)
9393
b.append(',');
9494
constexpr auto v =
@@ -106,7 +106,7 @@ constexpr void atom(string_builder &b, const T &t) {
106106
template <class Z> void fast_to_json_string(string_builder &b, const Z &z) {
107107
int i = 0;
108108
b.append('{');
109-
[:expand(std::meta::nonstatic_data_members_of(^Z)):] >> [&]<auto dm> {
109+
[:expand(std::meta::nonstatic_data_members_of(^^Z)):] >> [&]<auto dm> {
110110
if (i != 0)
111111
b.append(',');
112112
constexpr auto v =

include/simdjson/json_builder/string_builder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <string>
77
#include <string_view>
88
#include <vector>
9+
#include <memory>
910

1011
namespace simdjson {
1112

include/simdjson/json_builder/universal_formatter.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef SIMDJSON_SERIALIZATION_UNIVERSAL_FORMATTER_HPP
22
#define SIMDJSON_SERIALIZATION_UNIVERSAL_FORMATTER_HPP
3-
#include "simdjson/json_builder/string_builder.hpp"
3+
#include "simdjson/json_builder/string_builder.h"
4+
#include "simdjson/json_builder/json_builder.h"
45
#include <experimental/meta>
56
#include <format>
67
#include <print>
@@ -22,16 +23,16 @@ struct universal_formatter {
2223
first = false;
2324
};
2425

25-
[:expand(bases_of(^T)):] >> [&]<auto base> {
26+
[:expand(bases_of(^^T)):] >> [&]<auto base> {
2627
delim();
2728
sb.append(std::format("{}", (typename[:type_of(base):] const &)(t)));
2829
};
2930

30-
[:expand(nonstatic_data_members_of(^T)):] >> [&]<auto mem> {
31-
delim();
32-
sb.append(std::format("\"{}\":{}", name_of(mem),
33-
json_builder::atom(sb, t.[:mem:])));
34-
};
31+
// [:expand(nonstatic_data_members_of(^^T)):] >> [&]<auto mem> {
32+
// delim();
33+
// sb.append(std::format("\"{}\":{}", identifier_of(mem),
34+
// json_builder::atom(sb, t.[:mem:])));
35+
// };
3536

3637
sb.append('}');
3738
}

tests/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1+
CPMAddPackage(
2+
NAME GTest
3+
GITHUB_REPOSITORY google/googletest
4+
VERSION 1.15.2
5+
)
6+
17
add_compile_options(-Wall -Wextra -Weffc++ -Wsign-compare -Wshadow -Wwrite-strings -Wpointer-arith -Winit-self -Wconversion -Wno-sign-conversion)
28

39
add_executable(user_profile_tests user_profile_tests.cpp)
410
target_link_libraries(user_profile_tests nlohmann_json::nlohmann_json simdjson::serialization simdjson::simdjson)
511
add_test(user_profile_tests user_profile_tests)
612

713
add_executable(universal_formatter_tests universal_formatter_tests.cpp)
8-
target_link_libraries(universal_formatter_tests simdjson::serialization simdjson::simdjson)
14+
target_link_libraries(universal_formatter_tests simdjson::serialization simdjson::simdjson GTest::gtest_main)
915
add_test(universal_formatter_tests universal_formatter_tests)
Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
#include "simdjson/json_builder/universal_formatter.h"
2-
#include <iostream>
2+
#include <gtest/gtest.h>
33

4-
int main(){
5-
simdjson::json_builder::StringBuilder b;
6-
simdjson::json_builder::universal_formatter universal_formatter;
7-
return EXIT_SUCCESS;
8-
}
4+
TEST(UniversalFormatterTest, EmptyStruct) {
5+
struct Empty {};
6+
7+
Empty obj;
8+
simdjson::json_builder::universal_formatter universal_formatter;
9+
simdjson::json_builder::string_builder string_builder;
10+
universal_formatter.format(obj, string_builder);
11+
12+
EXPECT_EQ(string_builder.view(), "{}");
13+
}

tests/user_profile_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ template <auto B, auto E, typename F> constexpr void for_range(F &&f) {
2222
}
2323

2424
template <typename T> consteval auto member_info(int n) {
25-
return nonstatic_data_members_of(^T)[n];
25+
return nonstatic_data_members_of(^^T)[n];
2626
}
2727

2828
std::mt19937 rng(12345);
@@ -195,7 +195,7 @@ std::string nlohmann_serialize(const User &user) {
195195
template <typename T>
196196
bool compare(const T &user1, const T &user2, const std::string &json) {
197197
bool result = true;
198-
for_range<0, nonstatic_data_members_of(^T).size()>([&]<auto i>() {
198+
for_range<0, nonstatic_data_members_of(^^T).size()>([&]<auto i>() {
199199
constexpr auto mem = member_info<T>(i);
200200
if constexpr (std::equality_comparable<typename[:type_of(mem):]>) {
201201
if (user1.[:mem:] != user2.[:mem:]) {

0 commit comments

Comments
 (0)