There exist many similar questions for C, e.g. this one, but i'm searching for the simplest and most readable way in C++ to pass an C-array into a function without first defining a variable for it.
Given a
void f(double const* a)
these are not possible (but the first one is in C99):
f((double []){1,2}); // works in C
f({1,2}); // would be great but doesn't work in any language with C-arrays
Of course defining a variable first is always possible, but that's not what i'm looking for:
double a[] = { 1.2, 3.4 };
f(a);
However, it is possible to wrap things into a struct, f.e. like
struct A { double a[2]; };
f(A{2.3,4.5}.a);
and that type can be reused, so that's already a little win
but this still feels clumsy.
Is there a simpler and more readable way? In one of the current standards or maybe an upcoming one?
EDIT: Sorry, i didn't mention that before; i can't change the target api. A pointer to a double is expected.