eclipse-iceoryx / eclipse-iceoryx/iceoryx
Optimize cxx::optional for references or create a cxx::optional_ref
- Dominant language
- C++
- Stars
- 2.2k
- Forks
- 492
- Avg merge
- 18h 57m
- Merged PRs (30d)
- 1
Description
## Brief feature description
The memory consumption of cxx::optional with nullable types can be reduced by removing the m_hasValue flag and inferring that information from the stored pointer.
## Detailed information
A cxx::optional or cxx::optional doesn't need the m_hasValue flag, but can infer the information from the value being a nullptr.
It would be similar to a std::reference_wrapper, but with the advantage of being nullable so that instead of returning a raw pointer, a optional of a raw pointer or reference can be used. The benefit would be that when the optinoal contains a value, it would never be a nullptr and a developer can tell from the signature that the function might have a nulltopt.
Further information to consider when implementing:
- https://foonathan.net/2018/07/optional-reference/
- https://www.jonathanmueller.dev/talk/cppnow2018/
- https://www.fluentcpp.com/2018/10/02/pointers-references-optional-references-cpp/
- https://www.fluentcpp.com/2018/10/05/pros-cons-optional-references/
Contributor guide
Assessment
This issue has not been assessed yet.