mirror of
https://github.com/fmtlib/fmt.git
synced 2025-07-31 11:17:35 +02:00
Remove make_arg
This commit is contained in:
@ -2363,24 +2363,6 @@ constexpr unsigned long long make_descriptor() {
|
|||||||
: is_unpacked_bit | NUM_ARGS;
|
: 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>
|
template <typename Context, size_t NUM_ARGS>
|
||||||
using arg_t = conditional_t<NUM_ARGS <= max_packed_args, value<Context>,
|
using arg_t = conditional_t<NUM_ARGS <= max_packed_args, value<Context>,
|
||||||
basic_format_arg<Context>>;
|
basic_format_arg<Context>>;
|
||||||
@ -2401,7 +2383,7 @@ struct format_arg_store {
|
|||||||
template <typename... T>
|
template <typename... T>
|
||||||
FMT_CONSTEXPR FMT_ALWAYS_INLINE format_arg_store(T&... values)
|
FMT_CONSTEXPR FMT_ALWAYS_INLINE format_arg_store(T&... values)
|
||||||
: args{{named_args, NUM_NAMED_ARGS},
|
: 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;
|
int arg_index = 0, named_arg_index = 0;
|
||||||
FMT_APPLY_VARIADIC(
|
FMT_APPLY_VARIADIC(
|
||||||
init_named_arg(named_args, arg_index, named_arg_index, values));
|
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::value<Context> value_;
|
||||||
detail::type type_;
|
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>;
|
friend class basic_format_args<Context>;
|
||||||
|
|
||||||
using char_type = typename Context::char_type;
|
using char_type = typename Context::char_type;
|
||||||
|
@ -996,6 +996,12 @@ struct is_contiguous<basic_memory_buffer<T, SIZE, Allocator>> : std::true_type {
|
|||||||
|
|
||||||
FMT_END_EXPORT
|
FMT_END_EXPORT
|
||||||
namespace detail {
|
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 auto write_console(int fd, string_view text) -> bool;
|
||||||
FMT_API void print(std::FILE*, string_view);
|
FMT_API void print(std::FILE*, string_view);
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
@ -342,24 +342,24 @@ VISIT_TYPE(unsigned long, unsigned long long);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if FMT_BUILTIN_TYPES
|
#if FMT_BUILTIN_TYPES
|
||||||
# define CHECK_ARG(Char, expected, value) \
|
# define CHECK_ARG(expected, value) \
|
||||||
{ \
|
{ \
|
||||||
testing::StrictMock<mock_visitor<decltype(expected)>> visitor; \
|
testing::StrictMock<mock_visitor<decltype(expected)>> visitor; \
|
||||||
EXPECT_CALL(visitor, visit(expected)); \
|
EXPECT_CALL(visitor, visit(expected)); \
|
||||||
using iterator = fmt::basic_appender<Char>; \
|
|
||||||
auto var = value; \
|
auto var = value; \
|
||||||
fmt::detail::make_arg<fmt::basic_format_context<iterator, Char>>(var) \
|
fmt::basic_format_arg<fmt::format_context>( \
|
||||||
|
fmt::detail::arg_mapper<char>::map(var)) \
|
||||||
.visit(visitor); \
|
.visit(visitor); \
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
# define CHECK_ARG(Char, expected, value)
|
# define CHECK_ARG(expected, value)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define CHECK_ARG_SIMPLE(value) \
|
#define CHECK_ARG_SIMPLE(value) \
|
||||||
{ \
|
{ \
|
||||||
using value_type = decltype(value); \
|
using value_type = decltype(value); \
|
||||||
typename visit_type<value_type>::type expected = 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 {};
|
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());
|
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) {
|
TEST(arg_test, string_arg) {
|
||||||
char str_data[] = "test";
|
char str_data[] = "test";
|
||||||
char* str = str_data;
|
char* str = str_data;
|
||||||
const char* cstr = str;
|
const char* cstr = str;
|
||||||
CHECK_ARG(char, cstr, str);
|
CHECK_ARG(cstr, str);
|
||||||
|
|
||||||
auto sv = fmt::string_view(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) {
|
TEST(arg_test, pointer_arg) {
|
||||||
void* p = nullptr;
|
void* p = nullptr;
|
||||||
const void* cp = nullptr;
|
const void* cp = nullptr;
|
||||||
CHECK_ARG(char, cp, p);
|
CHECK_ARG(cp, p);
|
||||||
CHECK_ARG_SIMPLE(cp);
|
CHECK_ARG_SIMPLE(cp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -414,8 +414,8 @@ TEST(arg_test, volatile_pointer_arg) {
|
|||||||
const void* p = nullptr;
|
const void* p = nullptr;
|
||||||
volatile int* vip = nullptr;
|
volatile int* vip = nullptr;
|
||||||
const volatile int* cvip = nullptr;
|
const volatile int* cvip = nullptr;
|
||||||
CHECK_ARG(char, p, static_cast<volatile void*>(vip));
|
CHECK_ARG(p, static_cast<volatile void*>(vip));
|
||||||
CHECK_ARG(char, p, static_cast<const volatile void*>(cvip));
|
CHECK_ARG(p, static_cast<const volatile void*>(cvip));
|
||||||
}
|
}
|
||||||
|
|
||||||
struct check_custom {
|
struct check_custom {
|
||||||
@ -441,7 +441,7 @@ TEST(arg_test, custom_arg) {
|
|||||||
mock_visitor<fmt::basic_format_arg<fmt::format_context>::handle>;
|
mock_visitor<fmt::basic_format_arg<fmt::format_context>::handle>;
|
||||||
auto&& v = testing::StrictMock<visitor>();
|
auto&& v = testing::StrictMock<visitor>();
|
||||||
EXPECT_CALL(v, visit(_)).WillOnce(Invoke(check_custom()));
|
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) {
|
TEST(arg_test, visit_invalid_arg) {
|
||||||
|
Reference in New Issue
Block a user