Skip to content

Commit a10621a

Browse files
committed
update for r10
1 parent e5dc212 commit a10621a

File tree

6 files changed

+123
-114
lines changed

6 files changed

+123
-114
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ project(form
88
)
99

1010
set(CMAKE_CXX_STANDARD 26)
11-
set(CMAKE_CXX_FLAGS "-freflection -stdlib=libc++ ")
11+
set(CMAKE_CXX_FLAGS "-freflection -freflection-latest -stdlib=libc++ ")
1212

1313
file(
1414
DOWNLOAD

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# docker build . -t reflection --progress=plain
22
# clang++ -std=c++26 -freflection -stdlib=libc++
33

4-
FROM yaraslaut/clang-p2996:latest
5-
#FROM clang-p2996
4+
#FROM yaraslaut/clang-p2996:latest
5+
FROM clang-p2996
66

77
COPY . /mnt/src
88
WORKDIR /mnt/src

include/form/form.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ template <typename T> bool compare(T const &lhs, T const &rhs) {
8484

8585
template <auto refl> void run_par() {
8686
std::vector<std::thread> pool;
87-
[:util::expand(members_of(refl)):] >> [&]<auto mem> {
87+
[:util::expand(
88+
members_of(refl, std::meta::access_context::unchecked())):] >> [&]<auto mem> {
8889
pool.emplace_back(std::thread([&]() { [:mem:](); }));
8990
};
9091

@@ -94,14 +95,16 @@ template <auto refl> void run_par() {
9495
}
9596

9697
template <auto refl> void run_seq() {
97-
[:util::expand(members_of(refl)):] >> [&]<auto mem> { [:mem:](); };
98+
[:util::expand(members_of(
99+
refl, std::meta::access_context::unchecked())):] >> [&]<auto mem> { [:mem:](); };
98100
}
99101

100102
template <auto refl> void run_tests() {
101103
std::vector<std::thread> pool;
102-
[:util::expand(members_of(refl)
103-
):] >> [&]<auto mem>
104-
requires std::invocable<typename[:type_of(mem):]>
104+
[:util::expand(members_of(
105+
refl, std::meta::access_context::unchecked())):] >> [&]<auto mem>
106+
requires std::invocable<
107+
typename[:type_of(mem):]>
105108
{
106109
pool.emplace_back(std::thread([&]() {
107110
std::string out;
@@ -128,10 +131,13 @@ template <auto refl> void run_tests() {
128131

129132
template <typename S> consteval std::size_t get_padding() {
130133

131-
std::size_t pointer{offset_of(nonstatic_data_members_of(^^S)[0]).bytes};
134+
std::size_t pointer{static_cast<size_t>(
135+
offset_of(nonstatic_data_members_of(^^S, std::meta::access_context::unchecked())[0])
136+
.bytes)};
132137
std::size_t padding{0};
133138

134-
[:util::expand(nonstatic_data_members_of(^^S)):] >> [&, i = 0]<auto e>() {
139+
[:util::expand(nonstatic_data_members_of(
140+
^^S, std::meta::access_context::unchecked())):] >> [&, i = 0]<auto e>() {
135141
if (pointer == offset_of(e).bytes)
136142
pointer += size_of(e);
137143
else {

include/form/format.h

Lines changed: 79 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -153,92 +153,90 @@ struct Node {
153153
template <auto refl, typename T> std::string format(T const &t) {
154154
std::string out;
155155

156-
auto delim = [&, first = true]() mutable {
157-
if (!first) {
158-
std::format_to(std::back_inserter(out), [:refl:] ::delimiter());
159-
}
160-
first = false;
161-
};
162-
163-
std::format_to(std::back_inserter(out), "{}", [:refl:] ::start());
164-
util::for_range<0, util::number_of_base<T>()>([&]<auto I>() {
165-
constexpr auto base = util::base_info<T>(I);
166-
delim();
167-
std::format_to(std::back_inserter(out), "{}",
168-
format<refl>((typename [:type_of(base):] const & )(t)));
169-
});
170-
171-
util::for_range<0, util::number_of_members<T>()>([&]<auto I>() {
172-
constexpr auto mem = util::member_info<T>(I);
173-
constexpr auto name = util::name_of(mem);
174-
constexpr auto type = type_of(mem);
175-
delim();
176-
177-
if constexpr (std::is_arithmetic_v<[:type_of(mem):]>) {
178-
std::format_to(std::back_inserter(out),
179-
std::runtime_format([:refl:] ::withLevelKnown()), name,
180-
t.[:mem:]);
181-
} else if constexpr (std::same_as<[:type_of(mem):], std::string>) {
182-
std::format_to(std::back_inserter(out),
183-
std::runtime_format([:refl:] ::withLevelKnown()), name,
184-
std::format("\"{}\"", t.[:mem:]));
185-
} else if constexpr (std::is_constructible_v<
186-
std::formatter<[:type_of(mem):]>>) {
187-
std::format_to(std::back_inserter(out),
188-
std::runtime_format([:refl:] ::withLevelKnown()), name,
189-
std::format("{}", t.[:mem:]));
190-
} else {
191-
std::format_to(std::back_inserter(out),
192-
std::runtime_format([:refl:] ::withLevelNested()), name,
193-
[&]() {
194-
[:refl:] ::increase_level();
195-
return format<refl>(t.[:mem:]);
196-
}());
197-
[:refl:] ::decrease_level();
198-
}
199-
});
200-
std::format_to(std::back_inserter(out), "{}", [:refl:] ::end());
156+
// auto delim = [&, first = true]() mutable {
157+
// if (!first) {
158+
// std::format_to(std::back_inserter(out), "{}", [:refl:] ::delimiter());
159+
// }
160+
// first = false;
161+
// };
162+
163+
// std::format_to(std::back_inserter(out), "{}", [:refl:] ::start());
164+
// util::for_range<0, util::number_of_base<T>()>([&]<auto I>() {
165+
// constexpr auto base = util::base_info<T>(I);
166+
// delim();
167+
// std::format_to(std::back_inserter(out), "{}",
168+
// format<refl>((typename[:type_of(base):] const &)(t)));
169+
// });
170+
171+
// util::for_range<0, util::number_of_members<T>()>([&]<auto I>() {
172+
// constexpr auto mem = util::member_info<T>(I);
173+
// constexpr auto name = util::name_of(mem);
174+
// constexpr auto type = type_of(mem);
175+
// // delim();
176+
177+
// if constexpr (std::is_arithmetic_v<[:type_of(mem):]>) {
178+
// std::format_to(
179+
// std::back_inserter(out), [:refl:] ::withLevelKnown(), name, t.[:
180+
// mem:]);
181+
// } else if constexpr (std::same_as<[:type_of(mem):], std::string>) {
182+
// std::format_to(
183+
// std::back_inserter(out), [:refl:] ::withLevelKnown(), name,
184+
// std::format("\"{}\"", t.[:mem:]));
185+
// } else if constexpr (std::is_constructible_v<
186+
// std::formatter<[:type_of(mem):]>>) {
187+
// std::format_to(
188+
// std::back_inserter(out), [:refl:] ::withLevelKnown(), name,
189+
// std::format("{}", t.[:mem:]));
190+
// } else {
191+
// std::format_to(
192+
// std::back_inserter(out), [:refl:] ::withLevelNested(), name, [&]() {
193+
// [:refl:] ::increase_level();
194+
// return format<refl>(t.[:mem:]);
195+
// }());
196+
// [:refl:] ::decrease_level();
197+
// }
198+
// });
199+
// std::format_to(std::back_inserter(out), "{}", [:refl:] ::end());
201200

202201
return out;
203202
}
204203

205204
template <typename T> void from_node(auto const &node, T &t) {
206-
207-
util::for_range<0, util::number_of_members<T>()>([&]<auto I>() {
208-
constexpr auto mem = util::member_info<T>(I);
209-
auto name = std::string{util::name_of(mem)};
210-
// std::println("get value of: {}", name_of(mem));
211-
if constexpr (std::is_arithmetic_v<[:type_of(mem):]> ||
212-
std::same_as<[:type_of(mem):], std::string>) {
213-
t.[:mem:] = node[name].template as<[:type_of(mem):]>();
214-
} else if constexpr (std::is_constructible_v<
215-
std::formatter<[:type_of(mem):]>>) {
216-
// std::println("get value from std::format {}", name);
217-
constexpr auto type_of_mem =
218-
util::template_arguments<[:type_of(mem):]>(0);
219-
t.[:mem:] = util::construct_from<[:type_of(mem):]>(
220-
node[name].template as<[:type_of_mem:]>());
221-
} else {
222-
// std::println("diving into: {}", name);
223-
from_node(node[name], t.[:mem:]);
224-
}
225-
});
226-
227-
util::for_range<0, util::number_of_base<T>()>([&]<auto I>() {
228-
constexpr auto base = util::base_info<T>(I);
229-
util::for_range<0, util::number_of_members<[:type_of(base):]>()>(
230-
[&]<auto II>() {
231-
constexpr auto mem = util::member_info<[:type_of(base):]>(II);
232-
if constexpr (std::is_arithmetic_v<[:type_of(mem):]> ||
233-
std::same_as<[:type_of(mem):], std::string>) {
234-
auto name = std::string{util::name_of(mem)};
235-
t.[:mem:] = node[name].template as<[:type_of(mem):]>();
236-
} else if constexpr (std::formattable<[:type_of(mem):], char>) {
237-
} else {
238-
from_node(node[util::name_of(mem)], t.[:mem:]);
239-
}
240-
});
241-
});
205+
// util::for_range<0, util::number_of_members<T>()>([&]<auto I>() {
206+
// constexpr auto mem = util::member_info<T>(I);
207+
// auto name = std::string{util::name_of(mem)};
208+
// // std::println("get value of: {}", name_of(mem));
209+
// if constexpr (std::is_arithmetic_v<[:type_of(mem):]> ||
210+
// std::same_as<[:type_of(mem):], std::string>) {
211+
// t.[:mem:] = node[name].template as<[:type_of(mem):]>();
212+
// } else if constexpr (std::is_constructible_v<
213+
// std::formatter<[:type_of(mem):]>>) {
214+
// // std::println("get value from std::format {}", name);
215+
// constexpr auto type_of_mem =
216+
// util::template_arguments<[:type_of(mem):]>(0);
217+
// t.[:mem:] = util::construct_from<[:type_of(mem):]>(
218+
// node[name].template as<[:type_of_mem:]>());
219+
// } else {
220+
// // std::println("diving into: {}", name);
221+
// from_node(node[name], t.[:mem:]);
222+
// }
223+
// });
224+
225+
// util::for_range<0, util::number_of_base<T>()>([&]<auto I>() {
226+
// constexpr auto base = util::base_info<T>(I);
227+
// util::for_range<0, util::number_of_members<[:type_of(base):]>()>(
228+
// [&]<auto II>() {
229+
// constexpr auto mem = util::member_info<[:type_of(base):]>(II);
230+
// if constexpr (std::is_arithmetic_v<[:type_of(mem):]> ||
231+
// std::same_as<[:type_of(mem):], std::string>) {
232+
// auto name = std::string{util::name_of(mem)};
233+
// t.[:mem:] = node[name].template as<[:type_of(mem):]>();
234+
// } else if constexpr (std::formattable<[:type_of(mem):], char>) {
235+
// } else {
236+
// from_node(node[util::name_of(mem)], t.[:mem:]);
237+
// }
238+
// });
239+
// });
242240
}
243241

244242
template <typename T> std::string format_yaml(T const &t) {

include/form/util.h

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,25 @@ template <auto B, auto E, typename F> constexpr void for_range(F &&f) {
3636
}
3737

3838
template <typename T> consteval auto member_info(int n) {
39-
return nonstatic_data_members_of(^^T)[n];
39+
return nonstatic_data_members_of(^^T,
40+
std::meta::access_context::unchecked())[n];
4041
}
4142

4243
template <typename T> consteval auto base_info(int n) {
43-
return bases_of(^^T)[n];
44+
return bases_of(^^T, std::meta::access_context::unchecked())[n];
4445
}
4546

4647
template <typename T> consteval auto template_arguments(int n) {
4748
return template_arguments_of(^^T)[n];
4849
}
4950

5051
template <typename T> consteval auto number_of_members() {
51-
return nonstatic_data_members_of(^^T).size();
52+
return nonstatic_data_members_of(^^T, std::meta::access_context::unchecked())
53+
.size();
5254
}
5355

5456
template <typename T> consteval auto number_of_base() {
55-
return bases_of(^^T).size();
57+
return bases_of(^^T, std::meta::access_context::unchecked()).size();
5658
}
5759

5860
namespace __impl {
@@ -83,8 +85,10 @@ template <typename T, typename F> T construct_from(F f) { return T{f}; }
8385
**/
8486
consteval auto create_variant(auto reflection) {
8587

86-
return substitute(^^std::variant, std::vector{
87-
members_of(reflection)});
88+
return substitute(
89+
^^std::variant,
90+
std::vector{
91+
members_of(reflection, std::meta::access_context::unchecked())});
8892
}
8993

9094
template <typename Check, typename... T>
@@ -108,7 +112,8 @@ std::string_view get_before(std::string_view str, std::string_view delim) {
108112

109113
template <typename T> constexpr void print_members() {
110114
std::println("Members of: {}", util::name_of(^^T));
111-
[:util::expand(nonstatic_data_members_of(^^T)):] >> [&]<auto mem> {
115+
[:util::expand(nonstatic_data_members_of(
116+
^^T, std::meta::access_context::unchecked())):] >> [&]<auto mem> {
112117
std::println("{}", util::name_of(mem));
113118
};
114119
}

src/test.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@ template <typename T> void serialize(T const &val) {
131131
auto data_yaml = form::format_yaml(val);
132132
log::println("{}", data_yaml);
133133

134-
log::println("================================== [Serialized] JSON");
135-
auto data_json = form::format_json(val);
136-
log::println("{}", data_json);
134+
// log::println("================================== [Serialized] JSON");
135+
// auto data_json = form::format_json(val);
136+
// log::println("{}", data_json);
137137
}
138138

139139
template <typename T> void deserialize(T const &val) {
@@ -163,16 +163,16 @@ struct ConfigEntries {
163163

164164
namespace helper {
165165

166-
template <typename T, typename Tag = decltype([] {})> struct CreateUniqueT;
166+
template <typename T, typename Tag = decltype([] {})> struct CreateUniqueT {};
167167

168168
// clang-format off
169-
template <typename T> consteval bool CreateClass() {
170-
define_aggregate(^^T, {
171-
data_member_spec(^^int,{.name = "i"}),
172-
data_member_spec(^^int, {.name = "j"})
173-
});
174-
return true;
175-
}
169+
// template <typename T> consteval bool CreateClass() {
170+
// define_aggregate(^^T, {
171+
// data_member_spec(^^int,{.name = "i"}),
172+
// data_member_spec(^^int, {.name = "j"})
173+
// });
174+
// return true;
175+
// }
176176
// clang-format on
177177

178178
} // namespace helper
@@ -198,11 +198,11 @@ void testZ() {
198198
}
199199

200200
void testCreateClass() {
201-
using hidden_type = helper::CreateUniqueT<int>;
202-
constexpr bool create_hidden_type = helper::CreateClass<hidden_type>();
201+
// using hidden_type = helper::CreateUniqueT<int>;
202+
// constexpr bool create_hidden_type = helper::CreateClass<hidden_type>();
203203

204-
constexpr hidden_type value{};
205-
constexpr auto refl_of_value = ^^value;
204+
// constexpr hidden_type value{};
205+
// constexpr auto refl_of_value = ^^value;
206206
// util::print_members<[:type_of(refl_of_value):]>();
207207
}
208208

@@ -221,7 +221,7 @@ void testPageSize() {
221221
ps.lines = LineCount{5};
222222
ps.columns = ColumnCount{7};
223223
serialize(ps);
224-
deserialize(ps);
224+
// deserialize(ps);
225225
}
226226

227227
void testConfig() {

0 commit comments

Comments
 (0)