Add tl::expected wrapping#36
Conversation
|
@eholum I switched to using a copy-pasted version of Tried my hand at the macro, and even with the help of ChatGPT I couldn't quite figure it out. I kept getting a nanobind error about overloaded functions. Something like this: #define UNWRAP_EXPECTED(func_ptr) \
[](auto&& obj, auto&&... args) -> decltype(auto) { \
return unwrap_expected((std::forward<decltype(obj)>(obj).*func_ptr)(std::forward<decltype(args)>(args)...)); \
}
nanobind::class_<RRT>(m_rrt, "RRT")
.def("plan_expected", UNWRAP_EXPECTED(&RRT::plan_expected))yielded Maybe you can figure it out, but I think I'm now leaning towards writing the lambdas by hand. EDIT: BTW this doesn't seem to be fault of the macro, but rather the structure that makes this generic. For instance, this fails with the same error: nanobind::class_<RRT>(m_rrt, "RRT")
.def("plan_expected",
[](RRT& self, auto&&... args) {
return unwrap_expected(self::plan_expected(std::forward<decltype(args)>(args)...));
}) |
d5364f6 to
b837c29
Compare
idk who thinks that C++ can be hard to read because this is as straightforward as it comes. |
|
Maybe this could go horribly wrong if we end up with a ton of templates... but does that matter? Is that in any way worse than a macro? This one sparks joy: This one does not spark joy: |
|
That's beautiful! Please commit it to this branch. I was also thinking about the "what if the unexpected type is not a string?". For now, I would say we require it. If we ever need to use non-string types, then we can basically require that the type implements the |
Oooooh yeah that's a good idea and encompasses strings out of the box. |
|
@sea-bass how far did you get with this PR? And how far do you want it to get to call it "ready"? Happy to help out here if you're moving on with TOTG. |
Yeah I don't think it's ready and I don't have a whole lot of time the next few days (moving), so go ahead! I don't think this PR is very far away, though. As long as the mechanism is there to express expecteds, and it works well, it's fine. Standard usage across all the functionality can come later. |
|
Ok, converted two of the path_utils functions to use |
|
Oh. I submitted the initial PR so I can't approve my own. Time to send it. |
Resolves #9.
tl::expectedto the repoRRT::Plan,getPathLengths, andgetNormalizedPathScalingto usetl::expectedinstead of optionals