bitwizeshift / bitwizeshift/Lazy

Allow implicit conversion to T to be able to use as optional<T>.value_or(...) parameter

Open
#1 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
48
Forks
0
PR merge metrics
No merged PRs in 30d

Description

I'd like to be able to use Lazy as parameter for optional.value_or and make it be evaluated only if it is required.

Since the parameter must be implict convertible to T ( must verify is_convertible trait ), it should be good if
explicit operator reference() const;
is changed to
operator reference() const;

This will allow to do things like:
```
auto getFromFile = []() { std::cout << "File opened: "; return std::make_tuple("Lazy get the value from some file!");};
auto lazy_get_from_file = lazy::Lazy( getFromFile );

std::optional a= "Code value";
std::optional b;

std::cout << "::Not empty optional:: "<< a.value_or( lazy_get_from_file ) << std::endl;
std::cout << "::Empty optional:: " << b.value_or( lazy_get_from_file ) << std::endl;
```
and get this as output:

```
::Not empty optional:: Code value
::Empty optional:: File opened: Lazy get the value from some file!
```

Also bool converter should be removed and implemented as a member function like is_instantiated() in cast T is bool
Thanks

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.