1
1
#pragma once
2
2
3
- #include " fly/traits/traits.hpp"
4
3
#include " fly/types/string/detail/classifier.hpp"
5
4
#include " fly/types/string/detail/format_parse_context.hpp"
6
5
#include " fly/types/string/detail/format_specifier.hpp"
9
8
#include " fly/types/string/formatters.hpp"
10
9
11
10
#include < array>
11
+ #include < concepts>
12
12
#include < cstdint>
13
13
#include < string_view>
14
14
#include < type_traits>
@@ -153,7 +153,7 @@ class BasicFormatParameter
153
153
*
154
154
* @param value The user-defined value.
155
155
*/
156
- template <typename T, fly::enable_if<BasicFormatTraits::is_user_defined<T>> = 0 >
156
+ template <FormattableUserDefined T >
157
157
explicit constexpr BasicFormatParameter (const T &value) noexcept ;
158
158
159
159
/* *
@@ -164,7 +164,7 @@ class BasicFormatParameter
164
164
*
165
165
* @param value The string-like value.
166
166
*/
167
- template <typename T, fly::enable_if<fly::detail::is_like_supported_string<T>> = 0 >
167
+ template <FormattableString T >
168
168
explicit constexpr BasicFormatParameter (const T &value) noexcept ;
169
169
170
170
/* *
@@ -174,17 +174,37 @@ class BasicFormatParameter
174
174
*
175
175
* @param value The pointer value.
176
176
*/
177
- template <typename T, fly::enable_if<BasicFormatTraits::is_pointer<T>> = 0 >
177
+ template <FormattablePointer T >
178
178
explicit constexpr BasicFormatParameter (T value) noexcept ;
179
179
180
180
/* *
181
- * Constructor. Initialize the format parameter to store an arithmetic value.
181
+ * Constructor. Initialize the format parameter to store an integral value.
182
182
*
183
- * @tparam T The arithmetic type.
183
+ * @tparam T The integral type.
184
184
*
185
- * @param value The arithmetic value.
185
+ * @param value The integral value.
186
186
*/
187
- template <typename T, fly::enable_if<std::is_arithmetic<T>> = 0 >
187
+ template <FormattableIntegral T>
188
+ explicit constexpr BasicFormatParameter (T value) noexcept ;
189
+
190
+ /* *
191
+ * Constructor. Initialize the format parameter to store a floating-point value.
192
+ *
193
+ * @tparam T The floating-point type.
194
+ *
195
+ * @param value The floating-point value.
196
+ */
197
+ template <FormattableFloatingPoint T>
198
+ explicit constexpr BasicFormatParameter (T value) noexcept ;
199
+
200
+ /* *
201
+ * Constructor. Initialize the format parameter to store a boolean value.
202
+ *
203
+ * @tparam T The boolean type.
204
+ *
205
+ * @param value The boolean value.
206
+ */
207
+ template <FormattableBoolean T>
188
208
explicit constexpr BasicFormatParameter (T value) noexcept ;
189
209
190
210
/* *
@@ -274,13 +294,9 @@ class BasicFormatParameters
274
294
*
275
295
* @param parameters The format parameters to store.
276
296
*/
277
- template <typename FormatContext, typename ... ParameterTypes>
278
- constexpr inline auto make_format_parameters (ParameterTypes &&...parameters)
297
+ template <typename FormatContext, Formattable<FormatContext> ... ParameterTypes>
298
+ constexpr auto make_format_parameters (ParameterTypes &&...parameters)
279
299
{
280
- static_assert (
281
- (BasicFormatTraits::has_formatter_v<FormatContext, ParameterTypes> && ...),
282
- " A specialization of fly::Formatter<T, CharType> is required for all format parameters" );
283
-
284
300
return BasicFormatParameters<FormatContext, ParameterTypes...> {
285
301
std::forward<ParameterTypes>(parameters)...};
286
302
}
@@ -298,7 +314,7 @@ inline void format_user_defined_value(
298
314
Formatter formatter;
299
315
parse_context.lexer ().set_position (specifier.m_parse_index );
300
316
301
- if constexpr (FormatterWithParsing <decltype (parse_context), Formatter>)
317
+ if constexpr (FormattableWithParsing <decltype (parse_context), Formatter>)
302
318
{
303
319
formatter.parse (parse_context);
304
320
}
@@ -342,7 +358,7 @@ inline void format_standard_value(
342
358
{
343
359
typename FormatContext::template formatter_type<T> formatter (std::move (specifier));
344
360
345
- if constexpr (BasicFormatTraits::is_pointer_v <T>)
361
+ if constexpr (FormattablePointer <T>)
346
362
{
347
363
if constexpr (std::is_null_pointer_v<T>)
348
364
{
@@ -357,19 +373,19 @@ inline void format_standard_value(
357
373
formatter.format (static_cast <T>(const_cast <void *>(value.m_pointer )), context);
358
374
}
359
375
}
360
- else if constexpr (std::is_same_v <T, float >)
376
+ else if constexpr (std::same_as <T, float >)
361
377
{
362
378
formatter.format (value.m_float , context);
363
379
}
364
- else if constexpr (std::is_same_v <T, double >)
380
+ else if constexpr (std::same_as <T, double >)
365
381
{
366
382
formatter.format (value.m_double , context);
367
383
}
368
- else if constexpr (std::is_same_v <T, long double >)
384
+ else if constexpr (std::same_as <T, long double >)
369
385
{
370
386
formatter.format (value.m_long_double , context);
371
387
}
372
- else if constexpr (std::is_same_v <T, bool >)
388
+ else if constexpr (std::same_as <T, bool >)
373
389
{
374
390
formatter.format (value.m_bool , context);
375
391
}
@@ -385,27 +401,25 @@ inline void format_standard_value(
385
401
386
402
// ==================================================================================================
387
403
template <typename FormatContext>
388
- constexpr inline BasicFormatParameter<FormatContext>::BasicFormatParameter() noexcept :
404
+ constexpr BasicFormatParameter<FormatContext>::BasicFormatParameter() noexcept :
389
405
m_type (Type::Invalid),
390
406
m_value {.m_monostate {}}
391
407
{
392
408
}
393
409
394
410
// ==================================================================================================
395
411
template <typename FormatContext>
396
- template <typename T, fly::enable_if<BasicFormatTraits::is_user_defined<T>>>
397
- constexpr inline BasicFormatParameter<FormatContext>::BasicFormatParameter(const T &value) noexcept
398
- :
412
+ template <FormattableUserDefined T>
413
+ constexpr BasicFormatParameter<FormatContext>::BasicFormatParameter(const T &value) noexcept :
399
414
m_type (Type::UserDefined),
400
415
m_value {.m_user_defined {&value, format_user_defined_value<FormatContext, T>}}
401
416
{
402
417
}
403
418
404
419
// ==================================================================================================
405
420
template <typename FormatContext>
406
- template <typename T, fly::enable_if<fly::detail::is_like_supported_string<T>>>
407
- constexpr inline BasicFormatParameter<FormatContext>::BasicFormatParameter(const T &value) noexcept
408
- :
421
+ template <FormattableString T>
422
+ constexpr BasicFormatParameter<FormatContext>::BasicFormatParameter(const T &value) noexcept :
409
423
m_type (Type::String)
410
424
{
411
425
using U = std::remove_cvref_t <T>;
@@ -433,17 +447,36 @@ constexpr inline BasicFormatParameter<FormatContext>::BasicFormatParameter(const
433
447
434
448
// ==================================================================================================
435
449
template <typename FormatContext>
436
- template <typename T, fly::enable_if<BasicFormatTraits::is_pointer<T>> >
437
- constexpr inline BasicFormatParameter<FormatContext>::BasicFormatParameter(T value) noexcept :
450
+ template <FormattablePointer T >
451
+ constexpr BasicFormatParameter<FormatContext>::BasicFormatParameter(T value) noexcept :
438
452
m_type (Type::Pointer),
439
453
m_value {.m_standard {.m_pointer {value}, .m_format {format_standard_value<FormatContext, T>}}}
440
454
{
441
455
}
442
456
443
457
// ==================================================================================================
444
458
template <typename FormatContext>
445
- template <typename T, fly::enable_if<std::is_arithmetic<T>>>
446
- constexpr inline BasicFormatParameter<FormatContext>::BasicFormatParameter(T value) noexcept
459
+ template <FormattableIntegral T>
460
+ constexpr BasicFormatParameter<FormatContext>::BasicFormatParameter(T value) noexcept
461
+ {
462
+ m_value.m_standard .m_format = format_standard_value<FormatContext, T>;
463
+
464
+ if constexpr (std::is_signed_v<T>)
465
+ {
466
+ m_type = Type::SignedInt;
467
+ m_value.m_standard .m_signed_int = value;
468
+ }
469
+ else
470
+ {
471
+ m_type = Type::UnsignedInt;
472
+ m_value.m_standard .m_unsigned_int = value;
473
+ }
474
+ }
475
+
476
+ // ==================================================================================================
477
+ template <typename FormatContext>
478
+ template <FormattableFloatingPoint T>
479
+ constexpr BasicFormatParameter<FormatContext>::BasicFormatParameter(T value) noexcept
447
480
{
448
481
m_value.m_standard .m_format = format_standard_value<FormatContext, T>;
449
482
@@ -462,26 +495,20 @@ constexpr inline BasicFormatParameter<FormatContext>::BasicFormatParameter(T val
462
495
m_type = Type::LongDouble;
463
496
m_value.m_standard .m_long_double = value;
464
497
}
465
- else if constexpr (std::is_same_v<T, bool >)
466
- {
467
- m_type = Type::Bool;
468
- m_value.m_standard .m_bool = value;
469
- }
470
- else if constexpr (std::is_signed_v<T>)
471
- {
472
- m_type = Type::SignedInt;
473
- m_value.m_standard .m_signed_int = value;
474
- }
475
- else
476
- {
477
- m_type = Type::UnsignedInt;
478
- m_value.m_standard .m_unsigned_int = value;
479
- }
480
498
}
481
499
482
500
// ==================================================================================================
483
501
template <typename FormatContext>
484
- constexpr inline void BasicFormatParameter<FormatContext>::format(
502
+ template <FormattableBoolean T>
503
+ constexpr BasicFormatParameter<FormatContext>::BasicFormatParameter(T value) noexcept :
504
+ m_type (Type::Bool),
505
+ m_value {.m_standard {.m_bool {value}, .m_format {format_standard_value<FormatContext, T>}}}
506
+ {
507
+ }
508
+
509
+ // ==================================================================================================
510
+ template <typename FormatContext>
511
+ constexpr void BasicFormatParameter<FormatContext>::format(
485
512
BasicFormatParseContext<typename FormatContext::char_type> &parse_context,
486
513
FormatContext &context,
487
514
BasicFormatSpecifier<char_type> &&specifier) const
@@ -519,7 +546,7 @@ constexpr inline void BasicFormatParameter<FormatContext>::format(
519
546
// ==================================================================================================
520
547
template <typename FormatContext>
521
548
template <typename Visitor>
522
- constexpr inline auto BasicFormatParameter<FormatContext>::visit(Visitor &&visitor) const
549
+ constexpr auto BasicFormatParameter<FormatContext>::visit(Visitor &&visitor) const
523
550
{
524
551
switch (m_type)
525
552
{
@@ -555,7 +582,7 @@ inline BasicFormatParameter<FormatContext>::operator bool() const noexcept
555
582
556
583
// ==================================================================================================
557
584
template <typename FormatContext, typename ... ParameterTypes>
558
- constexpr inline BasicFormatParameters<FormatContext, ParameterTypes...>::BasicFormatParameters(
585
+ constexpr BasicFormatParameters<FormatContext, ParameterTypes...>::BasicFormatParameters(
559
586
ParameterTypes &&...parameters) noexcept :
560
587
m_parameters {FormatParameter {std::forward<ParameterTypes>(parameters)}...}
561
588
{
0 commit comments