You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
std::optional provides a modern way to express passing or returning value or not computed.
We are currently using many sentinel function arguments and return values including -1, nullptr and empty strings that require the user to read the docstring of the function to understand the argument or return value. These can be replaced with std::optional which is very explicit. An additional advantage is that nanobind has support for std::optional which results in consistent behaviour between the Python (typing.Optional) and C++ interfaces and a reduction in Python wrapper code complexity.
A first step would be identifying all typing.Optional arguments in Python which typically leads to a sentinel in C++.
Describe new/missing feature
std::optional
provides a modern way to express passing or returning value or not computed.We are currently using many sentinel function arguments and return values including
-1
,nullptr
and empty strings that require the user to read the docstring of the function to understand the argument or return value. These can be replaced withstd::optional
which is very explicit. An additional advantage is that nanobind has support forstd::optional
which results in consistent behaviour between the Python (typing.Optional
) and C++ interfaces and a reduction in Python wrapper code complexity.A first step would be identifying all
typing.Optional
arguments in Python which typically leads to a sentinel in C++.Examples of use are here:
#3328
#3322
Suggested user interface
No response
The text was updated successfully, but these errors were encountered: