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.
Подробнее здесь: https://stackoverflow.com/questions/287 ... ar-strings