refactor(fits_categorizer): don't override operator<< in std::

This commit is contained in:
Marcus Holland-Moritz 2025-03-15 12:20:19 +01:00
parent f1f57e9bc2
commit dc9e7df42d

View File

@ -32,7 +32,6 @@
#include <boost/program_options.hpp> #include <boost/program_options.hpp>
#include <fmt/format.h> #include <fmt/format.h>
#include <fmt/ostream.h>
#include <folly/Synchronized.h> #include <folly/Synchronized.h>
#include <folly/lang/Bits.h> #include <folly/lang/Bits.h>
@ -46,26 +45,24 @@
#include <dwarfs/writer/categorizer.h> #include <dwarfs/writer/categorizer.h>
#include <dwarfs/writer/compression_metadata_requirements.h> #include <dwarfs/writer/compression_metadata_requirements.h>
namespace std { template <>
struct fmt::formatter<std::endian> : formatter<std::string_view> {
inline ostream& operator<<(ostream& os, endian e) { template <typename FormatContext>
auto format(std::endian e, FormatContext& ctx) const {
std::string_view sv{"<unknown endian>"};
switch (e) { switch (e) {
case endian::big: case std::endian::little:
os << "big"; sv = "little";
break; break;
case endian::little: case std::endian::big:
os << "little"; sv = "big";
break; break;
default: default:
throw runtime_error("internal error: unhandled endianness value"); throw std::runtime_error("internal error: unhandled endianness value");
} }
return os; return formatter<std::string_view>::format(sv, ctx);
} }
};
} // namespace std
template <>
struct fmt::formatter<std::endian> : ostream_formatter {};
namespace dwarfs::writer { namespace dwarfs::writer {
@ -272,7 +269,7 @@ struct fits_metadata {
}; };
std::ostream& operator<<(std::ostream& os, fits_metadata const& m) { std::ostream& operator<<(std::ostream& os, fits_metadata const& m) {
os << "[" << m.endianness << "-endian, " os << "[" << fmt::format("{}", m.endianness) << "-endian, "
<< "bytes=" << static_cast<int>(m.bytes_per_sample) << ", " << "bytes=" << static_cast<int>(m.bytes_per_sample) << ", "
<< "unused=" << static_cast<int>(m.unused_lsb_count) << ", " << "unused=" << static_cast<int>(m.unused_lsb_count) << ", "
<< "components=" << static_cast<int>(m.component_count) << "]"; << "components=" << static_cast<int>(m.component_count) << "]";