[Idea] boost::optional::map for void f(...)
- Dominant language
- C++
- Stars
- 60
- Forks
- 75
- PR merge metrics
- No merged PRs in 30d
Description
As I work boost::optional I have a usecase, where I retrieve optional value and I do not necessary want to transform it, but just to use it if it is there, and if not to ignore it.
Let's assume scenario:
```
boost::optional GetTextOpt();
int stoi(std::string_view);
void SleepMillis(int);
```
In current implementation, workarounds are necessary, like:
```
// v1
if(auto res = GetTextOpt().map(stoi)) SleepMillis(res);
// v2
GetTextOpt().map(stoi).map([](int i){SleepMillis(i); return int{};})
```
Proposal:
Provide new method (e.g. boost::optional::consume) as implementation:
```
template
void consume(F f) [&,const&,&&]
{
if (this->has_value())
f(get());
}
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.