Commit cfe47b7b authored by Tom Niget's avatar Tom Niget

Add some useful functions to PyList

parent 5abca80c
......@@ -5,20 +5,31 @@
#ifndef TYPON_LIST_HPP
#define TYPON_LIST_HPP
#include <algorithm>
#include <ostream>
#include <vector>
// TODO: Hyrum's Law, maybe consider using composition instead to not expose
// that this is a std::vector?
template <typename T> class PyList {
public:
PyList(std::shared_ptr<std::vector<T>> &&v) : _v(std::move(v)) {}
PyList(std::vector<T> &&v) : _v(std::move(std::make_shared<std::vector<T>>(std::move(v)))) {}
PyList(std::vector<T> &&v)
: _v(std::move(std::make_shared<std::vector<T>>(std::move(v)))) {}
PyList(std::initializer_list<T> &&v) : _v(std::make_shared<std::vector<T>>(std::move(v))) {}
PyList(std::initializer_list<T> &&v)
: _v(std::make_shared<std::vector<T>>(std::move(v))) {}
PyList() : _v(std::make_shared<std::vector<T>>()) {}
auto begin() const { return _v->begin(); }
auto end() const { return _v->end(); }
auto append(const T &x) { _v->push_back(x); }
auto py_contains(const T &x) const {
return std::find(_v->begin(), _v->end(), x) != _v->end();
}
/*operator std::vector<T>() const {
return std::vector<T>(this->begin(), this->end());
}
......@@ -44,9 +55,7 @@ public:
s << ']';
}
void py_print(std::ostream &s) const {
py_repr(s);
}
void py_print(std::ostream &s) const { py_repr(s); }
PyList<T> operator+(const PyList<T> &other) const {
std::vector<T> v;
......
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