Quantcast
Viewing all articles
Browse latest Browse all 17825

How to have tamplates that only takes int[] ?

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: 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?

Viewing all articles
Browse latest Browse all 17825

Trending Articles