str/conv: Make formatter generic
Now it can be used for std::format or fmt::format.
Change-Id: If779dc7edfac2ee2829068be56b09a4f0ca18366
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/include/stdplus/net/addr/ether.hpp b/include/stdplus/net/addr/ether.hpp
index e0ff329..ee72572 100644
--- a/include/stdplus/net/addr/ether.hpp
+++ b/include/stdplus/net/addr/ether.hpp
@@ -1,4 +1,5 @@
#pragma once
+#include <fmt/core.h>
#include <net/ethernet.h>
#include <stdplus/hash.hpp>
diff --git a/include/stdplus/net/addr/ip.hpp b/include/stdplus/net/addr/ip.hpp
index d03f76f..1b0b2df 100644
--- a/include/stdplus/net/addr/ip.hpp
+++ b/include/stdplus/net/addr/ip.hpp
@@ -1,4 +1,5 @@
#pragma once
+#include <fmt/core.h>
#include <netinet/in.h>
#include <stdplus/hash.hpp>
diff --git a/include/stdplus/str/conv.hpp b/include/stdplus/str/conv.hpp
index cbf79d3..e0cf810 100644
--- a/include/stdplus/str/conv.hpp
+++ b/include/stdplus/str/conv.hpp
@@ -1,6 +1,4 @@
#pragma once
-#include <fmt/core.h>
-
#include <stdplus/str/buf.hpp>
#include <array>
@@ -125,9 +123,6 @@
template <typename T, typename CharT>
struct Format
{
- private:
- fmt::formatter<std::basic_string_view<CharT>> formatter;
-
public:
template <typename ParseContext>
constexpr auto parse(ParseContext& ctx)
@@ -136,9 +131,11 @@
}
template <typename FormatContext>
- auto format(auto v, FormatContext& ctx) const
+ constexpr auto format(auto v, FormatContext& ctx) const
{
- return formatter.format(ToStrHandle<T, CharT>{}(v), ctx);
+ auto h = ToStrHandle<T, CharT>{};
+ auto sv = h(v);
+ return std::copy(sv.begin(), sv.end(), ctx.out());
}
};