Skip to content

Commit f501442

Browse files
committed
std: optional pickable exposition for std::vector
1 parent 88d20bb commit f501442

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

include/eigenpy/std-vector.hpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,20 @@ struct EmptyPythonVisitor
417417
void visit(classT &) const {}
418418
};
419419

420+
namespace internal {
421+
template <typename vector_type, bool T_picklable = false>
422+
struct def_pickle_std_vector {
423+
static void run(bp::class_<vector_type> &) {}
424+
};
425+
426+
template <typename vector_type>
427+
struct def_pickle_std_vector<vector_type, true> {
428+
static void run(bp::class_<vector_type> &cl) {
429+
cl.def_pickle(PickleVector<vector_type>());
430+
}
431+
};
432+
} // namespace internal
433+
420434
///
421435
/// \brief Expose an std::vector from a type given as template argument.
422436
/// \tparam vector_type std::vector type to expose
@@ -426,7 +440,7 @@ struct EmptyPythonVisitor
426440
/// conversion from a Python list to a std::vector<T,Allocator>
427441
///
428442
template <class vector_type, bool NoProxy = false,
429-
bool EnableFromPythonListConverter = true>
443+
bool EnableFromPythonListConverter = true, bool pickable = true>
430444
struct StdVectorPythonVisitor {
431445
typedef typename vector_type::value_type value_type;
432446
typedef StdContainerFromPythonList<vector_type, NoProxy>
@@ -469,8 +483,9 @@ struct StdVectorPythonVisitor {
469483
"Copy constructor"))
470484

471485
.def(vector_indexing)
472-
.def(add_std_visitor)
473-
.def_pickle(PickleVector<vector_type>());
486+
.def(add_std_visitor);
487+
488+
internal::def_pickle_std_vector<vector_type, pickable>::run(cl);
474489
}
475490
if (EnableFromPythonListConverter) {
476491
// Register conversion

0 commit comments

Comments
 (0)