return PyrexTypes.error_type
if len(self.templates) != len(template_values):
error(pos, "%s templated type receives %d arguments, got %d" %
- (base_type, len(self.templates), len(template_values)))
- return PyrexTypes.error_type
+ (self.name, len(self.templates), len(template_values)))
+ return error_type
return self.specialize(dict(zip(self.templates, template_values)))
def specialize(self, values):
--- /dev/null
+#ifndef _OPERATORS_H_
+#define _OPERATORS_H_
+
+class Operators
+{
+public:
+ int value;
+ Operators() { }
+ Operators(int value) { this->value = value; }
+ virtual ~Operators() { }
+ Operators operator+(Operators f) { return Operators(this->value + f.value); }
+ Operators operator-(Operators f) { return Operators(this->value - f.value); }
+ Operators operator*(Operators f) { return Operators(this->value * f.value); }
+ Operators operator/(Operators f) { return Operators(this->value / f.value); }
+ bool operator<(Operators f) { return this->value < f.value; }
+ bool operator<=(Operators f) { return this->value <= f.value; }
+ bool operator==(Operators f) { return this->value == f.value; }
+ bool operator!=(Operators f) { return this->value != f.value; }
+ bool operator>(Operators f) { return this->value > f.value; }
+ bool operator>=(Operators f) { return this->value >= f.value; }
+ Operators operator>>(int v) { return Operators(this->value >> v); }
+ Operators operator<<(int v) { return Operators(this->value << v); }
+ Operators operator%(int v) { return Operators(this->value % v); }
+};
+
+#endif
--- /dev/null
+cdef extern from "operators.h":
+ cdef cppclass Operators:
+ __init__(int)
+ Operators __add__(Operators, Operators)
+ Operators __sub__(Operators, Operators)
+ Operators __mul__(Operators, Operators)
+ Operators __div__(Operators, Operators)
+ bool __lt__(Operators, Operators)
+ bool __le__(Operators, Operators)
+ bool __eq__(Operators, Operators)
+ bool __ne__(Operators, Operators)
+ bool __gt__(Operators, Operators)
+ bool __ge__(Operators, Operators)
+ Operators __rshift__(Operators, int)
+ Operators __lshift__(Operators, int)
+ Operators __mod__(Operators, int)
+
+cdef int v = 10
+cdef Operators a
+cdef Operators b
+cdef Operators c
+
+c = a + b
+c = a - b
+c = a * b
+c = a / b
+c = a << 2
+c = a >> 1
+c = b % 2
+a < b
+a <= b
+a == b
+a != b
+a > b
+a >= b
+
--- /dev/null
+#ifndef _TEMPLATES_H_
+#define _TEMPLATES_H_
+
+template<class T>
+class TemplateTest1
+{
+public:
+ T value;
+ int t;
+ TemplateTest1() { }
+ T getValue() { return value; }
+};
+
+template<class T, class U>
+class TemplateTest2
+{
+public:
+ T value1;
+ U value2;
+ TemplateTest2() { }
+ T getValue1() { return value1; }
+ U getValue2() { return value2; }
+};
+
+#endif
--- /dev/null
+cdef extern from "templates.h":
+ cdef cppclass TemplateTest1[T]:
+ __init__()
+ T value
+ int t
+ T getValue()
+
+ cdef cppclass TemplateTest2[T, U]:
+ __init__()
+ T value1
+ U value2
+ T getValue1()
+ U getValue2()
+
+cdef TemplateTest1[int] a
+cdef TemplateTest1[int]* b = new TemplateTest1[int]()
+
+cdef int c = a.getValue()
+c = b.getValue()
+
+cdef TemplateTest2[int, char] d
+cdef TemplateTest2[int, char]* e = new TemplateTest2[int, char]()
+
+c = d.getValue1()
+c = e.getValue2()
+
+cdef char f = d.getValue2()
+f = e.getValue2()