Skip to content

Commit d719663

Browse files
committed
Fix for nanobind v2.1.0 release
1 parent c7c2b2a commit d719663

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

bindings/python/src/optional-eigen-fix.hpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,19 @@ NAMESPACE_BEGIN(detail)
1414
/// https://github.com/wjakob/nanobind/issues/682#issuecomment-2310746145
1515
template<typename T>
1616
struct type_caster<std::optional<Eigen::Ref<const T>>>
17-
: optional_caster<std::optional<Eigen::Ref<const T>>>
1817
{
1918
using Ref = Eigen::Ref<const T>;
2019
using Optional = std::optional<Ref>;
21-
using Caster = typename type_caster::optional_caster::Caster;
20+
using Caster = make_caster<Ref>;
2221
using Map = typename Caster::Map;
2322
using DMap = typename Caster::DMap;
2423
NB_TYPE_CASTER(Optional, optional_name(Caster::Name))
2524

25+
type_caster()
26+
: value(std::nullopt)
27+
{
28+
}
29+
2630
bool from_python(handle src, uint8_t flags, cleanup_list* cleanup) noexcept
2731
{
2832
if (src.is_none())
@@ -39,6 +43,17 @@ struct type_caster<std::optional<Eigen::Ref<const T>>>
3943
value.emplace(caster.caster.operator Map());
4044
return true;
4145
}
46+
47+
template<typename T_>
48+
static handle from_cpp(T_&& value,
49+
rv_policy policy,
50+
cleanup_list* cleanup) noexcept
51+
{
52+
if (!value)
53+
return none().release();
54+
55+
return Caster::from_cpp(forward_like_<T_>(*value), policy, cleanup);
56+
}
4257
};
4358

4459
NAMESPACE_END(detail)

0 commit comments

Comments
 (0)