# cppclass string c++ class to create
# template_parameters None or [ExprNode] temlate parameters, if any
- def analyse_types(self, env):
+ def infer_type(self, env):
entry = env.lookup(self.cppclass)
if entry is None or not entry.is_cpp_class:
error(self.pos, "new operator can only be applied to a C++ class")
self.class_type = type
self.entry = constructor
self.type = constructor.type
+ return self.type
+
+ def analyse_types(self, env):
+ self.infer_type(env)
def generate_result_code(self, code):
pass
base_type = self.base.analyse_as_type(env)
if base_type and not base_type.is_pyobject:
if base_type.is_cpp_class:
- if isinstance(self.index, TupleExprNode):
+ if isinstance(self.index, TupleNode):
template_values = self.index.args
else:
template_values = [self.index]
if base_type.is_cpp_class:
# Templated class
- if len(self.keyword_args.key_value_pairs) != 0:
+ if self.keyword_args and self.keyword_args.key_value_pairs:
error(self.pos, "c++ templates cannot take keyword arguments");
self.type = PyrexTypes.error_type
else:
cfunc_call_tuple_args_T408
cascaded_list_unpacking_T467
compile.cpp_operators
-cpp_nested_templates
cppwrap
cpp_overload_wrapper
-from cython import dereference as deref
+from cython.operator cimport dereference as deref
cdef extern from "cpp_templates_helper.h":
cdef cppclass Wrap[T]:
def test_wrap_pair(int i, double x):
"""
>>> test_wrap_pair(1, 1.5)
- (1, 1.5, True, False)
+ (1, 1.5, True)
>>> test_wrap_pair(2, 2.25)
- (2, 2.25, True, False)
+ (2, 2.25, True)
"""
cdef Pair[int, double] *pair
cdef Wrap[Pair[int, double]] *wrap
try:
pair = new Pair[int, double](i, x)
- warp = new Wrap[Pair[int, double]](deref(pair))
+ wrap = new Wrap[Pair[int, double]](deref(pair))
return wrap.get().first(), wrap.get().second(), deref(wrap) == deref(wrap)
finally:
del pair, wrap
class Wrap {
T value;
public:
- Wrap(T v) { value = v; }
+ Wrap(T v) : value(v) { }
void set(T v) { value = v; }
T get(void) { return value; }
bool operator==(Wrap<T> other) { return value == other.value; }