You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#include ...
structpoint { double x, y; };
template <> structfmt::formatter<point> {
// Presentation format: 'f' - fixed, 'e' - exponential.char presentation = 'f';
// Parses format specifications of the form ['f' | 'e'].constexprautoparse(format_parse_context& ctx) -> decltype(ctx.begin()) {
// [ctx.begin(), ctx.end()) is a character range that contains a part of// the format string starting from the format specifications to be parsed,// e.g. in//// fmt::format("{:f} - point of interest", point{1, 2});//// the range will contain "f} - point of interest". The formatter should// parse specifiers until '}' or the end of the range. In this example// the formatter should parse the 'f' specifier and return an iterator// pointing to '}'.// Parse the presentation format and store it in the formatter:auto it = ctx.begin(), end = ctx.end();
if (it != end && (*it == 'f' || *it == 'e')) presentation = *it++;
// Check if reached the end of the range:if (it != end && *it != '}')
throwformat_error("invalid format");
// Return an iterator past the end of the parsed range:return it;
}
// Formats the point p using the parsed format specification (presentation)// stored in this formatter.template <typename FormatContext>
autoformat(const point& p, FormatContext& ctx) -> decltype(ctx.out()) {
// ctx.out() is an output iterator to write to.returnformat_to(
ctx.out(),
presentation == 'f' ? "({:.1f}, {:.1f})" : "({:.1e}, {:.1e})",
p.x, p.y);
}
};
then
point fuck = { 1, 2 };
fmt::print("{}\n", fuck);
Using MSVC++ Compiler 16.11.0 to build with C++20 (I use consteval in my code, so, I must use C++20), cause an compile error:
error C2668: “fmt::v8::format_to”: ambiguous call to overloaded function
It said that there are two functions can be called:
A simple code from https://fmt.dev/latest/api.html?highlight=formatter:
then
Using MSVC++ Compiler 16.11.0 to build with
C++20
(I useconsteval
in my code, so, I must use C++20), cause an compile error:It said that there are two functions can be called:
I don't know what happend, I need a help.
Thanks.
The text was updated successfully, but these errors were encountered: