eclipse-iceoryx / eclipse-iceoryx/iceoryx
Replace raw pointer with `std::reference_wrapper` where applicable
- Dominant language
- C++
- Stars
- 2.2k
- Forks
- 492
- Avg merge
- 18h 57m
- Merged PRs (30d)
- 1
Description
## Brief feature description
Currently we use raw pointer at several locations in our code base. This requires us to do `nullptr` checks even when we know that it is not possible to get a `nullptr` when the API is used in the correct way. Just returning a reference and expecting a reference as argument is not always possible or might be the source for different errors. By using `std::reference_wrapper` or an own implementation if the STL type does not give us the desired behavior, we can communicate that we do not expect `nullptr` and make our code base more robust towards a wrong usage.
## Detailed information
A problem with returning plain references is a potential unintentional copy on the caller side, e.g.
```cpp
Foo& getFoo() {
return fooFromShm();
}
void releaseFoo(Foo& foo) {
// code
}
int main() {
auto foo = getFoo(); // copy occurs here
releaseFoo(foo); // release a stack based object
}
```
To prevent this, a `std::reference_wrapper` might be returned instead of a plain reference.
Places where this could be used are the `SubscriberPort`, `PublisherPort`, `ClientPort`, `ServerPort`, and probably many more places.
### To Do
- [ ] remove `cxx::not_null`
### Related to
[#717 Replace cxx::not_null with reference wherever possible](https://github.com/eclipse-iceoryx/iceoryx/issues/717)
[#1101 Return user header ptr instead of reference](https://github.com/eclipse-iceoryx/iceoryx/issues/1101)
Contributor guide
Assessment
This issue has not been assessed yet.