Replace sentinel arguments and return values with std::optional
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 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++.
Examples of use are here:
https://github.com/FEniCS/dolfinx/pull/3328 https://github.com/FEniCS/dolfinx/pull/3322
Suggested user interface
No response
- ~~
set_bc: make $x_0$ optional (this will require some more changes, but should be able to remove a quite drastic code duplication problem)~~ (see #3434) -
locate_entities_boundaryandexterior_facet_indicescombinable - see https://github.com/FEniCS/dolfinx/pull/3283 - (
locate_dofs_topological)
This has been done for a number of interfaces and is recommended in the future.