отправная точка (которая работает):
Код: Выделить всё
#include
class foo_type{};
template struct fmt::formatter{
auto constexpr inline parse(fmt::format_parse_context& ctx)->fmt::format_parse_context::iterator{
return ctx.begin();
}
auto inline format(const foo_type&,fmt::format_context& ctx)const->fmt::format_context::iterator{
return ctx.out();
}
};
int main(){
foo_type foo;
fmt::print("{}",foo);
}
< /code>
Пока все хорошо. Однако: < /p>
fmt::print("{:{}}",foo,777);
< /code>
hields (в компиляторе Explorer): < /p>
: In function 'int main()':
:13:15: error: call to consteval function 'fmt::v10::basic_format_string("{:{}}")' is not a constant expression
13 | fmt::print("{:{}}",foo,777);
| ~~~~~~~~~~^~~~~~~~~~~~~~~~~
In file included from /opt/compiler-explorer/libs/fmt/10.2.1/include/fmt/format.h:49,
from :1:
:13:15: in 'constexpr' expansion of 'fmt::v10::basic_format_string("{:{}}")'
/opt/compiler-explorer/libs/fmt/10.2.1/include/fmt/core.h:2787:40: in 'constexpr' expansion of 'fmt::v10::detail::parse_format_string(((fmt::v10::basic_format_string*)this)->fmt::v10::basic_format_string::str_, fmt::v10::detail::format_string_checker(fmt::v10::basic_string_view(((const char*)s))))'
/opt/compiler-explorer/libs/fmt/10.2.1/include/fmt/core.h:2534:44: in 'constexpr' expansion of 'fmt::v10::detail::parse_replacement_field((p + -1), end, (* & handler))'
/opt/compiler-explorer/libs/fmt/10.2.1/include/fmt/core.h:2514:32: error: 'constexpr void fmt::v10::detail::format_string_checker::on_error(const char*) [with Char = char; Args = {foo_type, int}]' called in a constant expression
2514 | return handler.on_error("unknown format specifier"), end;
| ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/compiler-explorer/libs/fmt/10.2.1/include/fmt/core.h:2687:22: note: 'constexpr void fmt::v10::detail::format_string_checker::on_error(const char*) [with Char = char; Args = {foo_type, int}]' is not usable as a 'constexpr' function because:
2687 | FMT_CONSTEXPR void on_error(const char* message) {
| ^~~~~~~~
/opt/compiler-explorer/libs/fmt/10.2.1/include/fmt/core.h:2688:23: error: call to non-'constexpr' function 'void fmt::v10::detail::throw_format_error(const char*)'
2688 | throw_format_error(message);
| ~~~~~~~~~~~~~~~~~~^~~~~~~~~
/opt/compiler-explorer/libs/fmt/10.2.1/include/fmt/core.h:648:27: note: 'void fmt::v10::detail::throw_format_error(const char*)' declared here
648 | FMT_NORETURN FMT_API void throw_format_error(const char* message);
| ^~~~~~~~~~~~~~~~~~
Compiler returned: 1
, поэтому мне нужно написать свой собственный анализ и формат .
и мне нужно, чтобы поддерживать динамику, поддерживать Dynemic Arse. Уже два вопроса: < /p>
Как сделать его компиляцией с вложенными аргументами? < /li>
Тогда как я могу получить вышеупомянутые вложенные аргументы?>
Подробнее здесь: https://stackoverflow.com/questions/795 ... -formatter
Мобильная версия