Simplified version
class C {
public:
static constexpr std::array<C, 2> foo {{"1"_C, "2"_C}};
int x;
constexpr C(char c) { x=c; }
}
constexpr C operator"" _C(const char * str, size_t n) { return C(*str); }
This doesn't fly, because the literals are not understood at the line where the array is defined. But the free literal function can't be moved earlier because then C isn't known.
Is there a solution to this Gordian knot that doesn't involve adding variadic templates or something horrid like that into the code?
_C
is an allowed name, since it's underscore + uppercase letter, which is reserved for the implementation. – Xeo_C
is an identifier and not a name, as talked about here, so it is okay. The name would beoperator"" _C
. – Jesse Good#define _C _x
before the literal operator, if I doauto x = "hi"_C;
, I get a compiler error, while"hi"_x
works. – Xeo