Skip to content

Commit dc9789e

Browse files
committed
[std-vector] add container_traits struct
+ use ::allocator_type typedef by default, set as void for std::array
1 parent 58571e5 commit dc9789e

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

include/eigenpy/std-vector.hpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,20 @@ struct reference_arg_from_python<std::vector<Type, Allocator> &>
234234

235235
namespace eigenpy {
236236

237+
namespace details {
238+
/// Defines traits for the container, used in \struct StdContainerFromPythonList
239+
template <class Container>
240+
struct container_traits {
241+
// default behavior expects allocators
242+
typedef typename Container::allocator_type Allocator;
243+
};
244+
245+
template <typename _Tp, std::size_t Size>
246+
struct container_traits<std::array<_Tp, Size> > {
247+
typedef void Allocator;
248+
};
249+
}; // namespace details
250+
237251
///
238252
/// \brief Register the conversion from a Python list to a std::vector
239253
///
@@ -242,6 +256,7 @@ namespace eigenpy {
242256
template <typename vector_type, bool NoProxy>
243257
struct StdContainerFromPythonList {
244258
typedef typename vector_type::value_type T;
259+
typedef typename details::container_traits<vector_type>::Allocator Allocator;
245260

246261
/// \brief Check if obj_ptr can be converted
247262
static void *convertible(PyObject *obj_ptr) {

0 commit comments

Comments
 (0)