Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Deduce the array-sizes in a variadic template function

I try to write a constexpr function that accepts a variable number of C-Strings. And I want to deduce all of the sizes (here: L0 and LL) of the passed arrays. Looks like a stupid error I make there, but trying to do so, I get an error:

error: parameter packs not expanded with '...':
  204 | constexpr auto generate(const char (&s0)[L0], const char (&ss)[LL] ...) {
template<size_t L0, size_t... LL>
constexpr auto generate(const char (&s0)[L0], const char (&ss)[LL] ...) {
    constexpr size_t ll = (LL + ...);
    std::integral_constant<size_t, L0>::_;
    std::integral_constant<size_t, ll>::_;
        
    std::array<char, 1 + L0 + ll> r;
    return r;        
}

constexpr auto STR_X = generate("abc", "def");

This is done with gcc version 12.0 and -std=c++20.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The problem should be the expansion of ss (that is variadic too)

// ellipsis here ...........................................VVV
constexpr auto generate(const char (&s0)[L0], const char (& ... ss)[LL]) {
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading