Vento
Vento

Reputation: 215

Known sizes at compile time of variadic arrays

I am trying to deduce each array size at compile time, but I do not like the way which I came up with.

template <std::size_t Length>
struct __helper
{
    __helper(const char (&_sName)[Length])
    {
        memcpy(m_sName, _sName, Length);
    }

    char m_sName[Length];
};

template <std::size_t... Lengths>
static void foo(__helper<Lengths>... _namespaces)
{
}

I want to just pass text without __helper like foo("test", "test2") instead of foo(__helper("test"), __helper("test2")). Is there any way to do this as I want?

Upvotes: 0

Views: 72

Answers (1)

Jarod42
Jarod42

Reputation: 217275

Syntax to take variadic C array is:

template <std::size_t... Ns>
static void foo(char (&...args)[Ns])
{
// ...
}

Upvotes: 4

Related Questions