Contexpr для объединения двух или более струн CharC++

Программы на C++. Форум разработчиков
Ответить
Anonymous
 Contexpr для объединения двух или более струн Char

Сообщение Anonymous »

I'm trying to make a constexpr function that will concatenate an arbitrary number of char arrays by working from the following answer by Xeo, which concatenates two char arrays.

https://stackoverflow.com/a/13294458/1128289

Код: Выделить всё

#include 

template struct seq{};
template
struct gen_seq : gen_seq{};
template
struct gen_seq : seq{};

template
constexpr std::array concat(char const (&a1)[N1], char const (&a2)[N2], seq, seq){
return {{ a1[I1]..., a2[I2]... }};
}

template
constexpr std::array concat(char const (&a1)[N1], char const (&a2)[N2]){
return concat(a1, a2, gen_seq{}, gen_seq{});
}
< /code>

Моя попытка до сих пор: < /p>

#include 
#include 

template struct seq{};
template
struct gen_seq : gen_seq{};
template
struct gen_seq : seq{};

template
constexpr const std::array
concat_impl(
const char (&a1)[N1], const char (&a2)[N2], seq, seq)
{
return {{ a1[I1]..., a2[I2]... }};
}

template
constexpr const std::array
concat(const char (&a1)[N1], const char (&a2)[N2])
{
return concat_impl(a1, a2, gen_seq{}, gen_seq{});
}

template
constexpr auto
concat(const char(&a1)[N1], const char(&a2)[N2], const Us&... xs)
-> std::array
{
return concat(a1, concat(a2, xs...));
}

int main()
{
auto const s = concat("hi ", "there!");
std::cout  std::array
^                                                                                                   ~~~~~~
ctconcat.cpp:62:43: note: candidate function template not viable: requires 2 arguments, but 5 were provided
constexpr const std::array concat(const char (&a1)[N1], const char (&a2)[N2])
^
1 error generated.
Ошибки от GCC и Clang обоих указывают, что второй шаблон функции Concat не является кандидатом для выражения concat в выражении Decltype . Рассматривается только первый шаблон. Почему это и как это исправить?>

Подробнее здесь: https://stackoverflow.com/questions/287 ... ar-strings
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C++»