mirror of
https://github.com/fmtlib/fmt.git
synced 2026-05-04 03:40:49 +02:00
Add std::complex formatter
Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>
This commit is contained in:
committed by
Victor Zverovich
parent
9f3fc6e38b
commit
73f2b344b2
@@ -10,6 +10,7 @@
|
||||
|
||||
#include <atomic>
|
||||
#include <bitset>
|
||||
#include <complex>
|
||||
#include <cstdlib>
|
||||
#include <exception>
|
||||
#include <memory>
|
||||
@@ -585,5 +586,31 @@ struct formatter<std::atomic_flag, Char> : formatter<bool, Char> {
|
||||
};
|
||||
#endif // __cpp_lib_atomic_flag_test
|
||||
|
||||
FMT_EXPORT
|
||||
template <typename F, typename Char>
|
||||
struct formatter<std::complex<F>, Char> : nested_formatter<F, Char> {
|
||||
private:
|
||||
// Functor because C++11 doesn't support generic lambdas.
|
||||
struct writer {
|
||||
const formatter<std::complex<F>, Char>* f;
|
||||
const std::complex<F>& c;
|
||||
|
||||
template <typename OutputIt>
|
||||
FMT_CONSTEXPR auto operator()(OutputIt out) -> OutputIt {
|
||||
auto format =
|
||||
detail::string_literal<Char, '(', '{', '}', ',', '{', '}', ')'>{};
|
||||
return fmt::format_to(out, basic_string_view<Char>(format),
|
||||
f->nested(c.real()), f->nested(c.imag()));
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
template <typename FormatContext>
|
||||
auto format(const std::complex<F>& c, FormatContext& ctx) const
|
||||
-> decltype(ctx.out()) {
|
||||
return this->write_padded(ctx, writer{this, c});
|
||||
}
|
||||
};
|
||||
|
||||
FMT_END_NAMESPACE
|
||||
#endif // FMT_STD_H_
|
||||
|
||||
Reference in New Issue
Block a user