This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
template matching variable size array
- From: "Neal D. Becker" <ndbecker2 at verizon dot net>
- To: gcc at gcc dot gnu dot org
- Date: Fri, 07 May 2004 10:12:32 -0400
- Subject: template matching variable size array
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, " "));
}