:
void foo(uint8_t a[]) { ... }
- this is a function that accepts uint8_t*, not arrays - arrays are decomposed into pointers when using the function as arguments. The problem is that the list of initializers (e.g. {0x01, 0x02, 0x03}) cannot be converted to uint8_t*.
If you want to pass an arbitrary number from uint8_tto foo, an easy solution would be to use a newstd::initializer_list
void foo(std::initializer_list<uint8_t> a) { ... }
foo({0x01, 0x02, 0x03, 0x04, 0x05});
Or you can take a variational package and build an array from it from the inside:
template <typename... Args,
typename = std::enable_if_t<
all_true<std::is_convertible<Args, uint8_t>::value...>
>>
void foo(Args... elems) {
uint8_t a[] = {elems...};
}
This is a little different:
foo({0x01, 0x02, 0x03});
foo(0x01, 0x02, 0x03;
Barry source
share