Answer the question
In order to leave comments, you need to log in
Is it possible to convert the result of a constexpr function to a string?
There is a constexpr function that takes one string and returns a structure that stores another string. The question is whether it is possible to use a macro at compile time, instead of a structure, to get a string from the same structure.
As an example:
template <int sz>
struct dataString
{
wchar_t data[sz];
const int size = sz;
constexpr dataString() : data{ L'\0' } { };
};
template <int size>
constexpr dataString<size> encoder(const wchar_t* str) {
dataString<size> result;
for (int i = 0; i != result.size; i++) {
result.data[i] = str[i] ^ (wchar_t)key;
}
return result;
}
//Вот что получается:
constexpr dataString<4> test = encoder<4>(L"Test");
//А хочу получать, что-то такое:
wchar_t* test2 = TOTEXT(encoder<4>(L"Test");) \\ wchar_t* test2 = L"uxbF";
Answer the question
In order to leave comments, you need to log in
What does a macro do? Appends ".data"? Then in the code there is an extra semicolon inside the brackets. But in this case it should work. Why not make the datastring to wchar_t* conversion operator? Then the macro is not needed.
By the way, you can use custom literals to avoid counting characters each time ... although no, that would be fine for another.
Hmm, won't const int size = sz override constexpr? With an insufficient level of optimization
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question