template <typename T> void matrix_template_1() {
using matrix1_t = float __attribute__((matrix_type(T, T))); }
template <class C> void matrix_template_2() {
using matrix1_t = float __attribute__((matrix_type(C, C))); }
template <unsigned Rows, unsigned Cols>
void matrix_template_3() {
using matrix1_t = float __attribute__((matrix_type(Rows, Cols))); }
void instantiate_template_3() {
matrix_template_3<1, 10>();
matrix_template_3<0, 10>(); }
template <int Rows, unsigned Cols>
void matrix_template_4() {
using matrix1_t = float __attribute__((matrix_type(Rows, Cols))); }
void instantiate_template_4() {
matrix_template_4<2, 10>();
matrix_template_4<-3, 10>(); }
template <class T, unsigned long R, unsigned long C>
using matrix = T __attribute__((matrix_type(R, C)));
template <class T, unsigned long R>
void use_matrix(matrix<T, R, 10> &m) {}
template <class T, unsigned long C>
void use_matrix(matrix<T, 10, C> &m) {}
void test_ambigous_deduction1() {
matrix<float, 10, 10> m;
use_matrix(m);
}
template <class T, long R>
void type_conflict(matrix<T, R, 10> &m, T x) {}
void test_type_conflict(char *p) {
matrix<float, 10, 10> m;
type_conflict(m, p);
}
template <unsigned long R, unsigned long C>
matrix<float, R + 1, C + 2> use_matrix_2(matrix<int, R, C> &m) {}
template <unsigned long R, unsigned long C>
void use_matrix_2(matrix<int, R + 2, C / 2> &m1, matrix<float, R, C> &m2) {}
template <typename T, unsigned long R, unsigned long C>
void use_matrix_2(matrix<T, R + C, C> &m1, matrix<T, R, C - R> &m2) {}
template <typename T, unsigned long R>
void use_matrix_3(matrix<T, R - 2, R> &m) {}
void test_use_matrix_2() {
matrix<int, 5, 6> m1;
matrix<float, 5, 8> r1 = use_matrix_2(m1);
matrix<int, 4, 5> m2;
matrix<float, 5, 8> r2 = use_matrix_2(m2);
matrix<float, 3, 11> m3;
use_matrix_2(m1, m3);
matrix<int, 3, 4> m4;
use_matrix_2(m4, m4);
matrix<unsigned, 5, 5> m5;
use_matrix_3(m5);
}
template <typename T, unsigned R, unsigned C>
struct make1 {
typedef T __attribute__((matrix_type(R, C))) type;
};
void test_make1() {
make1<int, 5, 4>::type x;
}
template <typename T, unsigned R, unsigned C>
struct make2 {
typedef T __attribute__((matrix_type(R, C))) type; };
int test_make2() {
make2<int, 0, 1> x; }
template <typename T, unsigned R, unsigned C>
struct make3 {
typedef T __attribute__((matrix_type(R, C))) type; };
struct s {};
int test_make3() {
make3<s, 3, 3> x; }
template <typename T, T R, unsigned C>
struct make4 {
typedef T __attribute__((matrix_type(R, C))) type;
};
int test_make4() {
make4<int, 4, 5>::type x;
}
typedef int *int_ptr;
template <unsigned R, unsigned C>
struct make5 {
typedef int_ptr __attribute__((matrix_type(R, C))) type; };
template <int R, unsigned C>
struct make6 {
typedef int __attribute__((matrix_type(R, C))) type;
};
int test_make6() {
make6<4, 4>::type x;
make6<2, 2>::type y;
}
namespace Deduction {
template <typename T>
struct X0;
template <typename T, unsigned N>
struct X0<T __attribute__((matrix_type(N, 3)))> {
static const unsigned value = 0;
};
template <typename T>
struct X0<T __attribute__((matrix_type(4, 3)))> {
static const unsigned value = 1;
};
template <unsigned N>
struct X0<float __attribute__((matrix_type(N, 3)))> {
static const unsigned value = 2;
};
template <>
struct X0<float __attribute__((matrix_type(4, 3)))> {
static const unsigned value = 3;
};
typedef int __attribute__((matrix_type(2, 3))) int2;
typedef int __attribute__((matrix_type(4, 3))) int4;
typedef float __attribute__((matrix_type(2, 3))) float2;
typedef float __attribute__((matrix_type(4, 3))) float4;
int array0[X0<int2>::value == 0 ? 1 : -1];
int array1[X0<int4>::value == 1 ? 1 : -1];
int array2[X0<float2>::value == 2 ? 1 : -1];
int array3[X0<float4>::value == 3 ? 1 : -1];
}