I was doing this experiment, code below
#include <iostream>
using namespace std;
template<typename T>
void decay_test(T& arr)
{
cout << sizeof(arr) << endl;
cout << "arr has " << sizeof(arr) / sizeof(*arr) << " elements" << endl;
}
int main()
{
const auto size = 100;
int arr[size];
decay_test(arr);
return 0;
}
output:
Quote400
arr has 100 elements
Just wanted to see if it was possible to pass and array and it's size into a function with a single argument.
Seems it works, though how one would go about to make it in such a way that the template only takes in arrays of integers?