Commit cf67e0be authored by Tom Niget's avatar Tom Niget

Add some builtins to list

parent 94dee91f
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#include <algorithm> #include <algorithm>
#include <ostream> #include <ostream>
#include <vector> #include <vector>
//#include <nanobind/stl/detail/nb_list.h>
#include <pybind11/stl.h>
template <typename T> class PyList { template <typename T> class PyList {
public: public:
...@@ -30,6 +32,18 @@ public: ...@@ -30,6 +32,18 @@ public:
return std::find(_v->begin(), _v->end(), x) != _v->end(); return std::find(_v->begin(), _v->end(), x) != _v->end();
} }
auto size() const {
return _v->size();
}
void push_back(const T& value) {
_v->push_back(value);
}
void clear() {
_v->clear();
}
/*operator std::vector<T>() const { /*operator std::vector<T>() const {
return std::vector<T>(this->begin(), this->end()); return std::vector<T>(this->begin(), this->end());
} }
...@@ -82,4 +96,18 @@ template <typename T> PyList<T> list(std::initializer_list<T> &&v) { ...@@ -82,4 +96,18 @@ template <typename T> PyList<T> list(std::initializer_list<T> &&v) {
return PyList<T>(std::move(v)); return PyList<T>(std::move(v));
} }
namespace PYBIND11_NAMESPACE { namespace detail {
template <typename Type>
struct type_caster<PyList<Type>> : list_caster<PyList<Type>, Type> {};
}}
/*NAMESPACE_BEGIN(NB_NAMESPACE)
NAMESPACE_BEGIN(detail)
template <typename Type> struct type_caster<PyList<Type>>
: list_caster<PyList<Type>, Type> { };
NAMESPACE_END(detail)
NAMESPACE_END(NB_NAMESPACE)
*/
#endif // TYPON_LIST_HPP #endif // TYPON_LIST_HPP
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment