|
8 | 8 | #include "eigenpy/fwd.hpp" |
9 | 9 | #include "eigenpy/eigen-from-python.hpp" |
10 | 10 | #include <boost/optional.hpp> |
| 11 | +#ifdef EIGENPY_WITH_CXX17_SUPPORT |
| 12 | +#include <optional> |
| 13 | +#endif |
11 | 14 |
|
| 15 | +#ifndef EIGENPY_DEFAULT_OPTIONAL |
12 | 16 | #define EIGENPY_DEFAULT_OPTIONAL boost::optional |
| 17 | +#endif |
13 | 18 |
|
14 | 19 | namespace boost { |
15 | 20 | namespace python { |
16 | 21 | namespace converter { |
17 | 22 |
|
18 | 23 | template <typename T> |
19 | | -struct expected_pytype_for_arg<EIGENPY_DEFAULT_OPTIONAL<T> > |
| 24 | +struct expected_pytype_for_arg<boost::optional<T> > |
20 | 25 | : expected_pytype_for_arg<T> {}; |
21 | 26 |
|
| 27 | +#ifdef EIGENPY_WITH_CXX17_SUPPORT |
| 28 | +template <typename T> |
| 29 | +struct expected_pytype_for_arg<std::optional<T> > |
| 30 | + : expected_pytype_for_arg<T> {}; |
| 31 | +#endif |
| 32 | + |
22 | 33 | } // namespace converter |
23 | 34 | } // namespace python |
24 | 35 | } // namespace boost |
25 | 36 |
|
26 | 37 | namespace eigenpy { |
27 | 38 | namespace detail { |
28 | 39 |
|
| 40 | +/// Helper struct to decide which type is the "none" type for a specific optional<T> implementation. |
| 41 | +template<template <typename> class OptionalTpl> |
| 42 | +struct nullopt_helper {}; |
| 43 | + |
| 44 | +template<> |
| 45 | +struct nullopt_helper<boost::optional> { |
| 46 | + typedef boost::none_t type; |
| 47 | + static type value() { return boost::none; } |
| 48 | +}; |
| 49 | + |
| 50 | +#ifdef EIGENPY_WITH_CXX17_SUPPORT |
| 51 | +template<> |
| 52 | +struct nullopt_helper<std::optional> { |
| 53 | + typedef std::nullopt_t type; |
| 54 | + static type value() { return std::nullopt; } |
| 55 | +}; |
| 56 | +#endif |
| 57 | + |
29 | 58 | template <typename T, |
30 | 59 | template <typename> class OptionalTpl = EIGENPY_DEFAULT_OPTIONAL> |
31 | 60 | struct OptionalToPython { |
@@ -80,7 +109,7 @@ void OptionalFromPython<T, OptionalTpl>::construct( |
80 | 109 | ->storage.bytes; |
81 | 110 |
|
82 | 111 | if (obj_ptr == Py_None) { |
83 | | - new (storage) OptionalTpl<T>(boost::none); |
| 112 | + new (storage) OptionalTpl<T>(nullopt_helper<OptionalTpl>::value()); |
84 | 113 | } else { |
85 | 114 | const T value = bp::extract<T>(obj_ptr); |
86 | 115 | new (storage) OptionalTpl<T>(value); |
|
0 commit comments