32 :
public bp::vector_indexing_suite<Container, NoProxy, DerivedPolicies> {
34 typedef typename Container::value_type data_type;
35 typedef typename Container::value_type key_type;
36 typedef typename Container::size_type index_type;
37 typedef typename Container::size_type size_type;
38 typedef typename Container::difference_type difference_type;
39 typedef std::vector<data_type, SliceAllocator> slice_vector_type;
40 static constexpr std::size_t Size = std::tuple_size<Container>{};
42 template <
class Class>
43 static void extension_def(Class &) {}
46 static void delete_item(Container &, index_type) {
47 PyErr_SetString(PyExc_NotImplementedError,
48 "Cannot delete item from std::array type.");
49 bp::throw_error_already_set();
53 static void delete_slice(Container &, index_type, index_type) {
54 PyErr_SetString(PyExc_NotImplementedError,
55 "Cannot delete slice from std::array type.");
56 bp::throw_error_already_set();
59 static void set_slice(Container &container, index_type from, index_type to,
62 PyErr_SetString(PyExc_NotImplementedError,
63 "Setting this slice would insert into an std::array, " 64 "which is not supported.");
65 bp::throw_error_already_set();
67 std::fill(container.begin() + from, container.begin() + to, v);
72 static void set_slice(Container &container, index_type from, index_type to,
73 Iter first, Iter last) {
75 PyErr_SetString(PyExc_NotImplementedError,
76 "Setting this slice would insert into an std::array, " 77 "which is not supported.");
78 bp::throw_error_already_set();
80 if (
long(to - from) == std::distance(first, last)) {
81 std::copy(first, last, container.begin() + from);
83 PyErr_SetString(PyExc_NotImplementedError,
84 "Size of std::array slice and size of right-hand side " 85 "iterator are incompatible.");
86 bp::throw_error_already_set();
91 static bp::object get_slice(Container &container, index_type from,
93 if (from > to)
return bp::object(slice_vector_type());
94 slice_vector_type out;
95 for (
size_t i = from; i < to; i++) {
96 out.push_back(container[i]);
98 return bp::object(std::move(out));
113 typedef typename array_type::value_type value_type;
115 static ::boost::python::list tolist(array_type &self,
const bool deep_copy) {
116 return details::build_list<array_type, NoProxy>::run(self, deep_copy);
119 static void expose(
const std::string &class_name,
120 const std::string &doc_string =
"") {
124 template <
typename DerivedVisitor>
125 static void expose(
const std::string &class_name,
126 const bp::def_visitor<DerivedVisitor> &visitor) {
127 expose(class_name,
"", visitor);
130 template <
typename DerivedVisitor>
131 static void expose(
const std::string &class_name,
132 const std::string &doc_string,
133 const bp::def_visitor<DerivedVisitor> &visitor) {
135 bp::class_<array_type> cl(class_name.c_str(), doc_string.c_str());
136 cl.def(bp::init<const array_type &>(bp::args(
"self",
"other"),
137 "Copy constructor"));
141 cl.def(indexing_suite)
143 .def(
"tolist", tolist,
144 (bp::arg(
"self"), bp::arg(
"deep_copy") =
false),
145 "Returns the std::array as a Python list.");