Skip to content

Commit 81c74c2

Browse files
committed
Cleanup standard formatters
1 parent 4404dc0 commit 81c74c2

File tree

1 file changed

+32
-35
lines changed

1 file changed

+32
-35
lines changed

include/fmt/std.h

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@
1515
# include <atomic>
1616
# include <bitset>
1717
# include <complex>
18-
# include <cstdlib>
1918
# include <exception>
20-
# include <functional>
19+
# include <functional> // std::reference_wrapper
2120
# include <memory>
2221
# include <thread>
2322
# include <type_traits>
24-
# include <typeinfo>
25-
# include <utility>
23+
# include <typeinfo> // std::type_info
24+
# include <utility> // std::make_index_sequence
2625

2726
// Check FMT_CPLUSPLUS to suppress a bogus warning in MSVC.
2827
# if FMT_CPLUSPLUS >= 201703L
@@ -134,7 +133,7 @@ struct is_variant_like_<std::variant<Types...>> : std::true_type {};
134133

135134
// formattable element check.
136135
template <typename T, typename C> class is_variant_formattable_ {
137-
template <std::size_t... Is>
136+
template <size_t... Is>
138137
static std::conjunction<
139138
is_formattable<std::variant_alternative_t<Is, T>, C>...>
140139
check(std::index_sequence<Is...>);
@@ -152,7 +151,7 @@ template <typename Char, typename OutputIt>
152151
auto write_demangled_name(OutputIt out, const std::type_info& ti) -> OutputIt {
153152
# ifdef FMT_HAS_ABI_CXA_DEMANGLE
154153
int status = 0;
155-
std::size_t size = 0;
154+
size_t size = 0;
156155
std::unique_ptr<char, void (*)(void*)> demangled_name_ptr(
157156
abi::__cxa_demangle(ti.name(), nullptr, &size, &status), &std::free);
158157

@@ -191,7 +190,7 @@ auto write_demangled_name(OutputIt out, const std::type_info& ti) -> OutputIt {
191190
return detail::write_bytes<Char>(out, demangled_name_view);
192191
# elif FMT_MSC_VERSION
193192
const string_view demangled_name(ti.name());
194-
for (std::size_t i = 0; i < demangled_name.size(); ++i) {
193+
for (size_t i = 0; i < demangled_name.size(); ++i) {
195194
auto sub = demangled_name;
196195
sub.remove_prefix(i);
197196
if (sub.starts_with("enum ")) {
@@ -240,8 +239,31 @@ struct is_bit_reference_like<std::__bit_const_reference<C>> {
240239

241240
} // namespace detail
242241

242+
template <typename T, typename Deleter>
243+
auto ptr(const std::unique_ptr<T, Deleter>& p) -> const void* {
244+
return p.get();
245+
}
246+
template <typename T> auto ptr(const std::shared_ptr<T>& p) -> const void* {
247+
return p.get();
248+
}
249+
243250
#if FMT_CPP_LIB_FILESYSTEM
244251

252+
class path : public std::filesystem::path {
253+
public:
254+
auto display_string() const -> std::string {
255+
const std::filesystem::path& base = *this;
256+
return fmt::format(FMT_STRING("{}"), base);
257+
}
258+
auto system_string() const -> std::string { return string(); }
259+
260+
auto generic_display_string() const -> std::string {
261+
const std::filesystem::path& base = *this;
262+
return fmt::format(FMT_STRING("{:g}"), base);
263+
}
264+
auto generic_system_string() const -> std::string { return generic_string(); }
265+
};
266+
245267
template <typename Char> struct formatter<std::filesystem::path, Char> {
246268
private:
247269
format_specs specs_;
@@ -291,37 +313,20 @@ template <typename Char> struct formatter<std::filesystem::path, Char> {
291313
}
292314
};
293315

294-
class path : public std::filesystem::path {
295-
public:
296-
auto display_string() const -> std::string {
297-
const std::filesystem::path& base = *this;
298-
return fmt::format(FMT_STRING("{}"), base);
299-
}
300-
auto system_string() const -> std::string { return string(); }
301-
302-
auto generic_display_string() const -> std::string {
303-
const std::filesystem::path& base = *this;
304-
return fmt::format(FMT_STRING("{:g}"), base);
305-
}
306-
auto generic_system_string() const -> std::string { return generic_string(); }
307-
};
308-
309316
#endif // FMT_CPP_LIB_FILESYSTEM
310317

311-
template <std::size_t N, typename Char>
318+
template <size_t N, typename Char>
312319
struct formatter<std::bitset<N>, Char>
313320
: nested_formatter<basic_string_view<Char>, Char> {
314321
private:
315-
// Functor because C++11 doesn't support generic lambdas.
322+
// This is functor because C++11 doesn't support generic lambdas.
316323
struct writer {
317324
const std::bitset<N>& bs;
318325

319326
template <typename OutputIt>
320327
FMT_CONSTEXPR auto operator()(OutputIt out) -> OutputIt {
321-
for (auto pos = N; pos > 0; --pos) {
328+
for (auto pos = N; pos > 0; --pos)
322329
out = detail::write<Char>(out, bs[pos - 1] ? Char('1') : Char('0'));
323-
}
324-
325330
return out;
326331
}
327332
};
@@ -599,14 +604,6 @@ struct formatter<BitRef, Char,
599604
}
600605
};
601606

602-
template <typename T, typename Deleter>
603-
auto ptr(const std::unique_ptr<T, Deleter>& p) -> const void* {
604-
return p.get();
605-
}
606-
template <typename T> auto ptr(const std::shared_ptr<T>& p) -> const void* {
607-
return p.get();
608-
}
609-
610607
template <typename T, typename Char>
611608
struct formatter<std::atomic<T>, Char,
612609
enable_if_t<is_formattable<T, Char>::value>>

0 commit comments

Comments
 (0)