Код: Выделить всё
//ElementBuilder.h
namespace DataStructure{
class ElementBuilder: public std::enable_shared_from_this{
private:
std::shared_ptr element;
public:
ElementBuilder();
template
std::shared_ptr add(const T& value);
std::shared_ptr build();
};
template std::shared_ptr ElementBuilder::add(const int& value);
template std::shared_ptr ElementBuilder::add(const std::string& value);
template std::shared_ptr ElementBuilder::add(const double& value);
template std::shared_ptr ElementBuilder::add(const std::shared_ptr& value);
}
Вот Код Cython.
Код: Выделить всё
cdef extern from "utils/element_builder.h" namespace "DataStructure":
cdef cppclass _ElementBuilder "DataStructure::ElementBuilder":
_ElementBuilder()
# These work well if I compile without add[shared_ptr[_Element]]
shared_ptr[_ElementBuilder] add[int](int value)
shared_ptr[_ElementBuilder] add[string](string value)
# It fails if I try to compile with add[shared_ptr[_Element]]
shared_ptr[_ElementBuilder] add[shared_ptr[_Element]](shared_ptr[_Element] value)
Код: Выделить всё
_ElementВозможно, я смогу решить эту проблему, переобернув только ElementBuilder::add в новую функцию, а затем обернуть новую функцию Cython. При использовании этого подхода основная причина использования шаблонов, а именно обработка нескольких типов с помощью одной функции, становится ненужной. Есть ли хорошие решения для более эффективного устранения вышеуказанной ошибки?
Подробнее здесь: https://stackoverflow.com/questions/785 ... ith-cython
Мобильная версия