File tree 2 files changed +22
-1
lines changed
2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -205,6 +205,11 @@ template <ct_string Fmt> struct fmt_data {
205
205
constexpr static auto splits = split_specifiers<N + 1 >(fmt);
206
206
constexpr static auto last_cts = to_ct_string<splits[N].size()>(splits[N]);
207
207
};
208
+
209
+ template <typename T>
210
+ constexpr auto ct_format_as (T const &t) -> decltype(auto ) {
211
+ return (t);
212
+ }
208
213
} // namespace detail
209
214
210
215
template <ct_string Fmt,
@@ -223,7 +228,8 @@ constexpr auto ct_format = [](auto &&...args) {
223
228
};
224
229
225
230
auto const result = [&]<std::size_t ... Is>(std::index_sequence<Is...>) {
226
- return (format1.template operator ()<Is>(FWD (args)) + ... +
231
+ using detail::ct_format_as;
232
+ return (format1.template operator ()<Is>(ct_format_as (FWD (args))) + ... +
227
233
format_result{cts_t <data::last_cts>{}});
228
234
}(std::make_index_sequence<data::N>{});
229
235
return format_result{detail::convert_output<result.str .value , Output>(),
Original file line number Diff line number Diff line change @@ -223,3 +223,18 @@ TEST_CASE("num fmt specifiers", "[ct_format]") {
223
223
static_assert (stdx::num_fmt_specifiers<" {}" > == 1u );
224
224
static_assert (stdx::num_fmt_specifiers<" {} {}" > == 2u );
225
225
}
226
+
227
+ namespace user {
228
+ struct S {
229
+ int x;
230
+ };
231
+
232
+ constexpr auto ct_format_as (S const &s) {
233
+ return stdx::ct_format<" S: {}" >(s.x );
234
+ }
235
+ } // namespace user
236
+
237
+ TEST_CASE (" user-defined formatting" , " [ct_format]" ) {
238
+ auto r = stdx::ct_format<" Hello {}" >(user::S{42 });
239
+ CHECK (r == stdx::format_result{" Hello S: {}" _ctst, stdx::make_tuple (42 )});
240
+ }
You can’t perform that action at this time.
0 commit comments