A
Alf P. Steinbach
// As usual the error message directs one to the report the bug.
//
// And as usual there is absolutely no way to do so without paying for
// the privilege...
//
// Or using three or four hours to find the _current_ reporting page...
//
// Since I'm now using much time on reporting this compiler bug, please
// do also fix the __LINE__ macro.
//
// It does not work with some compiler options, which means e.g. Andrei
// Alexandrescu's ScopeGuard does not compile with this compiler.
#include <vector>
#include <iostream>
template< typename T, size_t N >
struct ArrayHolder
{
T elem[N];
};
template< typename T >
class VectorImpl
{
private:
std::vector<T> elem;
public:
template< size_t N >
VectorImpl( T const (&values)[N] ): elem( values, values+N ) {}
T& operator[]( size_t i ){ return elem.at( i ); }
T const& operator[]( size_t i ) const { return elem.at( i ); }
};
template< typename T >
class Vector: public VectorImpl< T >
{
public:
template< size_t N >
// This is a bug. It causes a compiler crash. That is, an ICE.
VectorImpl( T const (&values)[N] ): VectorImpl( values ) {}
};
int main()
{
typedef ArrayHolder<double, 6> DoubleArray6;
static DoubleArray6 const x = { 10, 20, 30, 40, 50, 60 };
static DoubleArray6 const xArray[] = { x };
Vector<DoubleArray6> v( xArray );
for( size_t i = 0; i < 6; ++i )
{
std::cout << v[0].elem << std::endl;
}
}
//
// And as usual there is absolutely no way to do so without paying for
// the privilege...
//
// Or using three or four hours to find the _current_ reporting page...
//
// Since I'm now using much time on reporting this compiler bug, please
// do also fix the __LINE__ macro.
//
// It does not work with some compiler options, which means e.g. Andrei
// Alexandrescu's ScopeGuard does not compile with this compiler.
#include <vector>
#include <iostream>
template< typename T, size_t N >
struct ArrayHolder
{
T elem[N];
};
template< typename T >
class VectorImpl
{
private:
std::vector<T> elem;
public:
template< size_t N >
VectorImpl( T const (&values)[N] ): elem( values, values+N ) {}
T& operator[]( size_t i ){ return elem.at( i ); }
T const& operator[]( size_t i ) const { return elem.at( i ); }
};
template< typename T >
class Vector: public VectorImpl< T >
{
public:
template< size_t N >
// This is a bug. It causes a compiler crash. That is, an ICE.
VectorImpl( T const (&values)[N] ): VectorImpl( values ) {}
};
int main()
{
typedef ArrayHolder<double, 6> DoubleArray6;
static DoubleArray6 const x = { 10, 20, 30, 40, 50, 60 };
static DoubleArray6 const xArray[] = { x };
Vector<DoubleArray6> v( xArray );
for( size_t i = 0; i < 6; ++i )
{
std::cout << v[0].elem << std::endl;
}
}