mirror of
https://github.com/fmtlib/fmt.git
synced 2026-02-05 17:30:06 +08:00
NFC: formatting fix
This commit is contained in:
parent
5487689a57
commit
d149787ade
@ -353,9 +353,7 @@ template <typename T, typename Char> struct is_range {
|
||||
* */
|
||||
|
||||
FMT_EXPORT
|
||||
template <typename T>
|
||||
struct is_container_adaptor : std::true_type {};
|
||||
|
||||
template <typename T> struct is_container_adaptor : std::true_type {};
|
||||
|
||||
namespace detail {
|
||||
|
||||
@ -780,7 +778,7 @@ template <typename T, typename Char>
|
||||
struct formatter<
|
||||
T, Char,
|
||||
enable_if_t<conjunction<detail::is_container_adaptor_like<T>,
|
||||
is_container_adaptor<T>, // -> added the sanity checker
|
||||
is_container_adaptor<T>,
|
||||
bool_constant<range_format_kind<T, Char>::value ==
|
||||
range_format::disabled>>::value>>
|
||||
: formatter<detail::all<typename T::container_type>, Char> {
|
||||
|
||||
@ -5,10 +5,6 @@
|
||||
//
|
||||
// For the license information refer to format.h.
|
||||
|
||||
#include "fmt/ranges.h"
|
||||
#include "fmt/ranges.h"
|
||||
#include "fmt/ranges.h"
|
||||
#include "fmt/ranges.h"
|
||||
#include "fmt/ranges.h"
|
||||
|
||||
#include <array>
|
||||
@ -21,8 +17,9 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "posix-mock.h"
|
||||
#include "fmt/base.h"
|
||||
#include "fmt/ranges.h"
|
||||
#include "posix-mock.h"
|
||||
|
||||
#if FMT_CPLUSPLUS > 201703L && FMT_HAS_INCLUDE(<ranges>)
|
||||
# include <ranges>
|
||||
@ -805,42 +802,40 @@ struct not_range {
|
||||
};
|
||||
static_assert(!fmt::is_formattable<not_range>{}, "");
|
||||
|
||||
namespace test_detail
|
||||
{
|
||||
template <typename T>
|
||||
struct partial_opt_out_wrapper
|
||||
{
|
||||
using container_type = std::vector<T>;
|
||||
std::vector<T> c = {1, 2, 3};
|
||||
auto begin() const {return c.begin(); }
|
||||
auto end() const {return c.end(); }
|
||||
namespace test_detail {
|
||||
template <typename T> struct partial_opt_out_wrapper {
|
||||
using container_type = std::vector<T>;
|
||||
std::vector<T> c = {1, 2, 3};
|
||||
|
||||
};
|
||||
typename std::vector<T>::const_iterator begin() const { return c.begin(); }
|
||||
typename std::vector<T>::const_iterator end() const { return c.end(); }
|
||||
};
|
||||
} // namespace test_detail
|
||||
|
||||
}
|
||||
namespace fmt
|
||||
{
|
||||
// disables is_range
|
||||
template <typename T>
|
||||
struct fmt::is_range<test_detail::partial_opt_out_wrapper<T>, char> : std::false_type{};
|
||||
// opt-out of the container adaptor format
|
||||
template <typename T>
|
||||
struct fmt::is_container_adaptor<test_detail::partial_opt_out_wrapper<T>> : std::false_type{};
|
||||
}
|
||||
//a custom partial specializtion
|
||||
namespace fmt {
|
||||
template <typename T>
|
||||
struct fmt::formatter<test_detail::partial_opt_out_wrapper<T>>
|
||||
{
|
||||
constexpr auto parse(fmt::format_parse_context& ctx) { return ctx.begin(); }
|
||||
auto format(const test_detail::partial_opt_out_wrapper<T>& val, fmt::format_context& ctx) const
|
||||
struct is_range<test_detail::partial_opt_out_wrapper<T>, char>
|
||||
: std::false_type {};
|
||||
|
||||
template <typename T>
|
||||
struct is_container_adaptor<test_detail::partial_opt_out_wrapper<T>>
|
||||
: std::false_type {};
|
||||
} // namespace fmt
|
||||
|
||||
template <typename T>
|
||||
struct fmt::formatter<test_detail::partial_opt_out_wrapper<T>> {
|
||||
fmt::format_parse_context::iterator parse(fmt::format_parse_context& ctx)
|
||||
{
|
||||
return fmt::format_to(ctx.out(), "PartialOptOut(size={})", val.c.size());
|
||||
return ctx.begin();
|
||||
}
|
||||
|
||||
fmt::format_context::iterator format(const test_detail::partial_opt_out_wrapper<T>& val,
|
||||
fmt::format_context& ctx) const {
|
||||
return fmt::format_to(ctx.out(), "PartialOptOut(size={})", val.c.size());
|
||||
}
|
||||
};
|
||||
TEST(ranges_test, container_adaptor_partial_specialization)
|
||||
{
|
||||
|
||||
TEST(ranges_test, container_adaptor_partial_specialization) {
|
||||
test_detail::partial_opt_out_wrapper<int> obj;
|
||||
EXPECT_EQ(fmt::format("{}", obj), "PartialOptOut(size=3)");
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user