Remove make_arg

This commit is contained in:
Victor Zverovich 2024-09-04 14:42:25 -07:00
parent 2a257798d4
commit 5f438c967e
3 changed files with 24 additions and 38 deletions

View File

@ -2363,24 +2363,6 @@ constexpr unsigned long long make_descriptor() {
: is_unpacked_bit | NUM_ARGS;
}
template <bool PACKED, typename Context, typename T, FMT_ENABLE_IF(PACKED)>
FMT_CONSTEXPR auto make_arg(T& val) -> value<Context> {
return {arg_mapper<typename Context::char_type>::map(val)};
}
template <typename Context, typename T>
FMT_CONSTEXPR auto make_arg(T& val) -> basic_format_arg<Context> {
auto arg = basic_format_arg<Context>();
arg.type_ = stored_type_constant<T, Context>::value;
arg.value_ = make_arg<true, Context>(val);
return arg;
}
template <bool PACKED, typename Context, typename T, FMT_ENABLE_IF(!PACKED)>
FMT_CONSTEXPR inline auto make_arg(T& val) -> basic_format_arg<Context> {
return make_arg<Context>(val);
}
template <typename Context, size_t NUM_ARGS>
using arg_t = conditional_t<NUM_ARGS <= max_packed_args, value<Context>,
basic_format_arg<Context>>;
@ -2401,7 +2383,7 @@ struct format_arg_store {
template <typename... T>
FMT_CONSTEXPR FMT_ALWAYS_INLINE format_arg_store(T&... values)
: args{{named_args, NUM_NAMED_ARGS},
make_arg<NUM_ARGS <= max_packed_args, Context>(values)...} {
arg_mapper<typename Context::char_type>::map(values)...} {
int arg_index = 0, named_arg_index = 0;
FMT_APPLY_VARIADIC(
init_named_arg(named_args, arg_index, named_arg_index, values));
@ -2543,8 +2525,6 @@ template <typename Context> class basic_format_arg {
detail::value<Context> value_;
detail::type type_;
template <typename Ctx, typename T>
friend FMT_CONSTEXPR auto detail::make_arg(T& value) -> basic_format_arg<Ctx>;
friend class basic_format_args<Context>;
using char_type = typename Context::char_type;

View File

@ -996,6 +996,12 @@ struct is_contiguous<basic_memory_buffer<T, SIZE, Allocator>> : std::true_type {
FMT_END_EXPORT
namespace detail {
template <typename Context, typename T>
FMT_CONSTEXPR auto make_arg(T& val) -> basic_format_arg<Context> {
return {arg_mapper<typename Context::char_type>::map(val)};
}
FMT_API auto write_console(int fd, string_view text) -> bool;
FMT_API void print(std::FILE*, string_view);
} // namespace detail

View File

@ -342,24 +342,24 @@ VISIT_TYPE(unsigned long, unsigned long long);
#endif
#if FMT_BUILTIN_TYPES
# define CHECK_ARG(Char, expected, value) \
{ \
testing::StrictMock<mock_visitor<decltype(expected)>> visitor; \
EXPECT_CALL(visitor, visit(expected)); \
using iterator = fmt::basic_appender<Char>; \
auto var = value; \
fmt::detail::make_arg<fmt::basic_format_context<iterator, Char>>(var) \
.visit(visitor); \
# define CHECK_ARG(expected, value) \
{ \
testing::StrictMock<mock_visitor<decltype(expected)>> visitor; \
EXPECT_CALL(visitor, visit(expected)); \
auto var = value; \
fmt::basic_format_arg<fmt::format_context>( \
fmt::detail::arg_mapper<char>::map(var)) \
.visit(visitor); \
}
#else
# define CHECK_ARG(Char, expected, value)
# define CHECK_ARG(expected, value)
#endif
#define CHECK_ARG_SIMPLE(value) \
{ \
using value_type = decltype(value); \
typename visit_type<value_type>::type expected = value; \
CHECK_ARG(char, expected, value) \
CHECK_ARG(expected, value) \
}
template <typename T> class numeric_arg_test : public testing::Test {};
@ -391,22 +391,22 @@ TYPED_TEST(numeric_arg_test, make_and_visit) {
CHECK_ARG_SIMPLE(std::numeric_limits<TypeParam>::max());
}
TEST(arg_test, char_arg) { CHECK_ARG(char, 'a', 'a'); }
TEST(arg_test, char_arg) { CHECK_ARG('a', 'a'); }
TEST(arg_test, string_arg) {
char str_data[] = "test";
char* str = str_data;
const char* cstr = str;
CHECK_ARG(char, cstr, str);
CHECK_ARG(cstr, str);
auto sv = fmt::string_view(str);
CHECK_ARG(char, sv, std::string(str));
CHECK_ARG(sv, std::string(str));
}
TEST(arg_test, pointer_arg) {
void* p = nullptr;
const void* cp = nullptr;
CHECK_ARG(char, cp, p);
CHECK_ARG(cp, p);
CHECK_ARG_SIMPLE(cp);
}
@ -414,8 +414,8 @@ TEST(arg_test, volatile_pointer_arg) {
const void* p = nullptr;
volatile int* vip = nullptr;
const volatile int* cvip = nullptr;
CHECK_ARG(char, p, static_cast<volatile void*>(vip));
CHECK_ARG(char, p, static_cast<const volatile void*>(cvip));
CHECK_ARG(p, static_cast<volatile void*>(vip));
CHECK_ARG(p, static_cast<const volatile void*>(cvip));
}
struct check_custom {
@ -441,7 +441,7 @@ TEST(arg_test, custom_arg) {
mock_visitor<fmt::basic_format_arg<fmt::format_context>::handle>;
auto&& v = testing::StrictMock<visitor>();
EXPECT_CALL(v, visit(_)).WillOnce(Invoke(check_custom()));
fmt::detail::make_arg<fmt::format_context>(test).visit(v);
fmt::basic_format_arg<fmt::format_context>(test).visit(v);
}
TEST(arg_test, visit_invalid_arg) {