template matching variable size array
Neal D. Becker
ndbecker2@verizon.net
Fri May 7 15:16:00 GMT 2004
g++34 supports variable size arrays. But, how can I make a template that
matches them? I have tried several things, but none works. Here is one
example that doesn't work. Is there a solution?
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
template< typename T, std::size_t sz >
inline const T* begin( const T (&array)[sz] )
{
return array;
}
template< typename T, std::size_t sz >
inline T* begin( T (&array)[sz] )
{
return array;
}
int F (int size) {
int a[size];
copy (begin (a), begin (a)+size, ostream_iterator<int> (cout, " "));
}
More information about the Gcc
mailing list