This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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, " "));
}




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]