Consider the following function which takes a reference to an array of a size N deduced at compile time:
template <size_t N>
void array_consumer(unsigned const (&source)[N]) {
// ...
}
I want to call it with an array initializer like this:
array_consumer({1u, 2u, 3u, 4u});
This works, but I don't want to specify the u after every value (the actual arrays may be much longer). Is there something I can do to the function signature or at the call site to avoid this?
Note that I need the array to actually be of unsigned type inside array_consumer (and I don't really want to make a copy) so changing the signature to int const (&source)[N]) doesn't work.
uafter every value. I assume you are using GCC as that seems to be the only compiler I could test that would complain about this. IMHO this must be a compilerbug as [dcl.init.list] § 7.4 should explicitly allow this. Seems to be fixed in current trunk: godbolt.org/g/5gNwWn. The question is, of course, if updating or changing compilers is an option for you…usuffixes. Then select the whole initializer and replace,byu,(and fix the last value manually).