Skip to content

Commit ff37b6c

Browse files
committed
Prefer "user-defined" over "generic" in formatting language
Some places refer to non-standard formatting types as "user-defined", others as "generic". For consistency, use "user-defined" everywhere. This avoids confusion with the similarly "general" floating-point presentation type.
1 parent d86a638 commit ff37b6c

9 files changed

+70
-70
lines changed

fly/types/string/detail/format_parameter_type.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace fly::detail {
1111
*/
1212
enum class ParameterType : std::uint8_t
1313
{
14-
Generic,
14+
UserDefined,
1515
Character,
1616
String,
1717
Pointer,
@@ -59,7 +59,7 @@ constexpr ParameterType infer_parameter_type()
5959
}
6060
else
6161
{
62-
return ParameterType::Generic;
62+
return ParameterType::UserDefined;
6363
}
6464
}
6565

fly/types/string/detail/format_parameters.hpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ class BasicFormatParameter
197197
enum class Type : std::uint8_t
198198
{
199199
Invalid,
200-
Generic,
200+
UserDefined,
201201
String,
202202
Pointer,
203203
SignedInt,
@@ -211,7 +211,7 @@ class BasicFormatParameter
211211
union Value
212212
{
213213
MonoState m_monostate;
214-
UserDefinedValue<FormatContext> m_generic;
214+
UserDefinedValue<FormatContext> m_user_defined;
215215
StringValue<FormatContext> m_string;
216216
StandardValue<FormatContext> m_standard;
217217
};
@@ -345,8 +345,8 @@ template <
345345
BasicFormatTraits::is_default_formatted_enum<T>>>
346346
constexpr inline BasicFormatParameter<FormatContext>::BasicFormatParameter(const T &value) noexcept
347347
:
348-
m_type(Type::Generic),
349-
m_value {.m_generic {&value, format_user_defined_value<FormatContext, T>}}
348+
m_type(Type::UserDefined),
349+
m_value {.m_user_defined {&value, format_user_defined_value<FormatContext, T>}}
350350
{
351351
}
352352

@@ -442,8 +442,8 @@ constexpr inline void BasicFormatParameter<FormatContext>::format(FormatContext
442442
{
443443
switch (m_type)
444444
{
445-
case Type::Generic:
446-
m_value.m_generic.m_format(m_value.m_generic.m_value, context);
445+
case Type::UserDefined:
446+
m_value.m_user_defined.m_format(m_value.m_user_defined.m_value, context);
447447
break;
448448
case Type::String:
449449
m_value.m_string.m_format(m_value.m_string.m_value, m_value.m_string.m_size, context);
@@ -469,8 +469,8 @@ constexpr inline auto BasicFormatParameter<FormatContext>::visit(Visitor &&visit
469469
{
470470
switch (m_type)
471471
{
472-
case Type::Generic:
473-
return visitor(m_value.m_generic);
472+
case Type::UserDefined:
473+
return visitor(m_value.m_user_defined);
474474
case Type::String:
475475
return visitor(m_value.m_string);
476476
case Type::Pointer:

fly/types/string/detail/format_specifier.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ namespace fly::detail {
102102
* Strong enumeration types - If an overload of operator<< is defined, valid presentations
103103
* are: none, "s". Else, valid presentations are: none, "c", b", "B", "o", "d", "x", "X".
104104
*
105-
* Other (generic) types - Valid presentations: none. An overload of operator<< must be
105+
* Other user-defined types - Valid presentations: none. An overload of operator<< must be
106106
* defined for generic types.
107107
*
108108
* For details on each presentation type, see the above links.

fly/types/string/detail/format_string.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,9 @@ constexpr auto BasicFormatString<CharType, ParameterTypes...>::parse_specifier()
155155
FormatSpecifier specifier {};
156156
specifier.m_position = m_context.next_position();
157157

158-
// TODO: For now, generic format parameters must be formatted with "{}".
158+
// TODO: For now, user-defined format parameters must be formatted with "{}".
159159
if (auto parameter_type = m_context.parameter_type(specifier.m_position);
160-
parameter_type && parameter_type != ParameterType::Generic)
160+
parameter_type && parameter_type != ParameterType::UserDefined)
161161
{
162162
if (m_context.lexer().consume_if(s_colon))
163163
{

fly/types/string/detail/string_traits.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,10 @@ struct BasicFormatTraits
179179
static inline constexpr bool is_default_formatted_enum_v = is_default_formatted_enum<T>::value;
180180

181181
/**
182-
* Trait to classify a type as a generic type.
182+
* Trait to classify a type as a user-defined type.
183183
*/
184184
template <typename T, typename U = std::remove_cvref_t<T>>
185-
using is_generic = std::negation<std::disjunction<
185+
using is_user_defined = std::negation<std::disjunction<
186186
detail::is_like_supported_string<T>,
187187
is_pointer<T>,
188188
is_integral<T>,
@@ -191,7 +191,7 @@ struct BasicFormatTraits
191191
is_default_formatted_enum<T>>>;
192192

193193
template <typename T>
194-
static inline constexpr bool is_generic_v = is_generic<T>::value;
194+
static inline constexpr bool is_user_defined_v = is_user_defined<T>::value;
195195
};
196196

197197
} // namespace fly::detail

fly/types/string/string.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -422,12 +422,12 @@ class BasicString
422422
* from the format string type. If the type differs, the format parameter is transcoded to
423423
* the type of the format string.
424424
*
425-
* 3. Any generic type for which an operator<< overload is defined will be converted to a
426-
* string using that overload.
425+
* 3. Any user-defined type for which an operator<< overload is defined will be converted to
426+
* a string using that overload.
427427
*
428428
* 4. Formatting of strong enumeration types defaults to the format of the enumeration's
429429
* underlying type. However, if an overload of operator<< is defined, the type is treated
430-
* as a generic type according to (3) above.
430+
* as a user-defined type according to (3) above.
431431
*
432432
* 5. This implementation is exceptionless. Any error encountered (such as failed transcoding
433433
* in (2) above) results in the format parameter that caused the error to be dropped.

fly/types/string/string_formatters.hpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ template <typename T, typename CharType = char, typename SFINAE = bool>
3535
struct Formatter;
3636

3737
template <typename T, typename CharType>
38-
struct Formatter<T, CharType, fly::enable_if<detail::BasicFormatTraits::is_generic<T>>>
38+
struct Formatter<T, CharType, fly::enable_if<detail::BasicFormatTraits::is_user_defined<T>>>
3939
{
4040
/**
41-
* Format a single replacement field with the provided generic value.
41+
* Format a single replacement field with the provided user-defined value.
4242
*
43-
* Currently, rather than supporting a set of std::formatter specializations, the generic value
44-
* will be converted to a string via the streaming operator. The resulting string will then be
45-
* formatted using the string formatting overload.
43+
* Currently, rather than supporting a set of std::formatter specializations, the user-defined
44+
* value will be converted to a string via the streaming operator. The resulting string will
45+
* then be formatted using the string formatting overload.
4646
*
4747
* @tparam FormatParameter The type of the formatting context.
4848
*
@@ -250,7 +250,7 @@ struct Formatter<T, CharType, fly::enable_if<std::is_same<T, bool>>>
250250
template <typename T, typename CharType>
251251
template <typename FormatContext>
252252
inline void
253-
Formatter<T, CharType, fly::enable_if<detail::BasicFormatTraits::is_generic<T>>>::format(
253+
Formatter<T, CharType, fly::enable_if<detail::BasicFormatTraits::is_user_defined<T>>>::format(
254254
const T &value,
255255
FormatContext &context)
256256
{

test/types/string/format.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ namespace {
2020

2121
#define FMT(format) FLY_ARR(char_type, format)
2222

23-
struct GenericType
23+
struct UserDefinedType
2424
{
2525
};
2626

27-
[[maybe_unused]] std::ostream &operator<<(std::ostream &stream, const GenericType &)
27+
[[maybe_unused]] std::ostream &operator<<(std::ostream &stream, const UserDefinedType &)
2828
{
29-
stream << "GenericType";
29+
stream << "UserDefinedType";
3030
return stream;
3131
}
3232

@@ -469,10 +469,10 @@ CATCH_TEMPLATE_TEST_CASE("FormatTypes", "[string]", char, wchar_t, char8_t, char
469469
return !value.empty();
470470
};
471471

472-
CATCH_SECTION("Generic types may be formatted without presentation type")
472+
CATCH_SECTION("User-defined types may be formatted without presentation type")
473473
{
474-
GenericType gt {};
475-
test_format(FMT("{}"), FMT("GenericType"), gt);
474+
UserDefinedType gt {};
475+
test_format(FMT("{}"), FMT("UserDefinedType"), gt);
476476
test_format(FMT("{}"), FMT("One"), UserFormattedEnum::One);
477477
test_format(FMT("{}"), FMT("Two"), UserFormattedEnum::Two);
478478
}

0 commit comments

Comments
 (0)