Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Defining a function that takes a std::array as a parameter [duplicate]

Tags:

c++

arrays

Basic question here, with (hopefully) a simple answer: I'm trying to write a function whose first argument is a std::array, but with an arbitrary size.

void f(array<int> x) {
    //do stuff
}

isn't valid, because I need a size for array<int, #>. Is there a way to get around this?

like image 593
CSGregorian Avatar asked Jul 10 '14 17:07

CSGregorian


1 Answers

The only way is to make f a function template :

template <size_t N>
void f(array<int, N> x) {
    //do stuff
}
like image 75
Quentin Avatar answered Oct 07 '22 10:10

Quentin