Skip to content

Commit 44f8bdc

Browse files
committed
[std-array] implement tolist() for std::array
1 parent cc30e46 commit 44f8bdc

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

include/eigenpy/std-array.hpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,10 @@ template <typename array_type, bool NoProxy = false,
109109
std::allocator<typename array_type::value_type> >
110110
struct StdArrayPythonVisitor {
111111
typedef typename array_type::value_type value_type;
112-
/// Fixed size of the array, known at compile time
113-
static constexpr std::size_t Size = std::tuple_size<array_type>{};
112+
113+
static ::boost::python::list tolist(array_type &self) {
114+
return details::build_list<array_type, NoProxy>::run(self);
115+
}
114116

115117
static void expose(const std::string &class_name,
116118
const std::string &doc_string = "") {
@@ -133,8 +135,10 @@ struct StdArrayPythonVisitor {
133135
"Copy constructor"));
134136

135137
array_indexing_suite<array_type, NoProxy, SliceAllocator> indexing_suite;
136-
cl.def(indexing_suite);
137-
cl.def(visitor);
138+
cl.def(indexing_suite)
139+
.def(visitor)
140+
.def("tolist", tolist, bp::arg("self"),
141+
"Returns the std::array as a Python list.");
138142
}
139143
}
140144
};

unittest/std_array.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ BOOST_PYTHON_MODULE(std_array) {
3030

3131
enableEigenPy();
3232

33-
StdArrayPythonVisitor<std::array<int, 3> >::expose("StdArr3_int");
33+
StdArrayPythonVisitor<std::array<int, 3>, true>::expose("StdArr3_int");
3434
StdVectorPythonVisitor<std::vector<int>, true>::expose("StdVec_int");
3535

3636
exposeStdArrayEigenSpecificType<VectorXd, 2>("VectorXd");

0 commit comments

Comments
 (0)