I've just installed gcc-4.8.1 and was pretty excited when I realised I can do -std=c++1y and get multiline constexpr. I'm curious to know, is there anyway to make this work?
#include <array>
constexpr auto operator "" _a1 (const char* text, const size_t size) -> std::array<char,size> {
std::array<char,size>() blah;
std::strncpy(blah.data(), test, size);
// do some stuff to blah at compile time
return blah;
}
int main() {
auto blah = "hello world"_a2;
}
But I get a big horrible:
$ g++ test.cpp -std=gnu++1y -Wall -Werror -Wextra -Weffc++ -pedantic
test.cpp:3:100: error: use of parameter ‘size’ outside function body
constexpr auto operator "" _a1 (const char* text, const size_t size) -> std::array<char,size> {
^
test.cpp:3:100: error: use of parameter ‘size’ outside function body
test.cpp:3:100: error: use of parameter ‘size’ outside function body
test.cpp:3:104: error: template argument 2 is invalid
constexpr auto operator "" _a1 (const char* text, const size_t size) -> std::array<char,size> {
^
test.cpp: In function ‘int main()’:
test.cpp:26:17: error: unable to find string literal operator ‘operator"" _a1’
auto blah = "hello world"_a1;
Is there anyway to make this happen? I can't return a std::string from a constexpr and there doesn't appear to be anything I can do with templates or decltype. Is there anyway to get a constant expression from a parameter?