I have a function of the following signature:
void foo(int argc, char const * const argv[]);
I would like to call it in a concise way, similar, but not necessary identical as below:
foo(3, {"one", "two", "three"});
I know that C supports compound literals just for this purpose (reference).
I also know how to solve the problem using templates (reference).
However, my problem is slightly different. The function signature is fixed - it normally takes arguments passed to main and the size of the array is not predefined. I am writing tests for this function and in my case the passed arrays are known at compile-time.
Is there a way to call foo without using temporary variables or wrapper functions like below?
char const * array[3] = {"one", "two", "three"};
foo(3, array);
template<int N>
void wrapper(char const * const (&array)[N])
{
foo(N, array);
}
std::arrayorstd::vector. That's going to make your life simpler.argcandargvto astd::array? You can't. I already have a wrapper that takesstd::vector, but I would like to eliminate it if possible.initializer_list?enable_if<true, char const*[]>::type{"one", "two", "three"}? Why wouldn't it work?