Open JohelEGP opened 8 months ago
There is a way to make @enum
able to be interpolated (https://cpp2.godbolt.org/z/xa8oo74qK):
command: @enum type = {
count;
filter;
}
template<> struct std::formatter<command> : formatter<string> {
auto format(command c, auto&& ctx) const {
return formatter<string>::format(c.to_string(), CPP2_FORWARD(ctx));
}
};
main: () = {
std::cout << "(command::count:)$\n";
}
But you need contextual knowledge to add the :
to the string.
Title:
@enum
value can't be interpolated.Minimal reproducer (https://cpp2.godbolt.org/z/bc16anzhP):
Commands:
```bash cppfront main.cpp2 clang++18 -std=c++23 -stdlib=libc++ -lc++abi -pedantic-errors -Wall -Wextra -Wconversion -Werror=unused-result -Werror=unused-value -Werror=unused-parameter -I . main.cpp ```Expected result: Interpolation to use the generated
to_string
member function.Actual result and error:
Cpp2 lowered to Cpp1:
```C++ //=== Cpp2 type declarations ==================================================== #include "cpp2util.h" #line 1 "/app/example.cpp2" class command; #line 2 "/app/example.cpp2" //=== Cpp2 type definitions and function declarations =========================== #line 1 "/app/example.cpp2" class command { private: cpp2::i8 _value; private: constexpr command(cpp2::in