mirror of
https://github.com/TartanLlama/optional.git
synced 2025-07-29 17:37:13 +02:00
Update readme
This commit is contained in:
22
README.md
22
README.md
@ -1,5 +1,5 @@
|
||||
# optional
|
||||
Single header implementation of `std::optional` with functional-style extensions.
|
||||
Single header implementation of `std::optional` with functional-style extensions and support for references.
|
||||
|
||||
Clang + GCC: [](https://travis-ci.org/TartanLlama/optional)
|
||||
MSVC: [](https://ci.appveyor.com/project/TartanLlama/optional)
|
||||
@ -66,6 +66,26 @@ The interface is the same as `std::optional`, but the following member functions
|
||||
- `take`: returns the current value, leaving the optional empty.
|
||||
* `opt_string.take().map(&std::string::size); //opt_string now empty;`
|
||||
|
||||
In addition to those member functions, optional references are also supported:
|
||||
|
||||
```
|
||||
int i = 42;
|
||||
tl::optional<int&> o = i;
|
||||
*o == 42; //true
|
||||
i = 12;
|
||||
*o = 12; //true
|
||||
&*o == &i; //true
|
||||
```
|
||||
|
||||
Assignment has rebind semantics rather than assign-through semantics:
|
||||
|
||||
```
|
||||
int j = 8;
|
||||
o = j;
|
||||
|
||||
&*o == &j; //true
|
||||
```
|
||||
|
||||
### Compiler support
|
||||
|
||||
Tested on:
|
||||
|
Reference in New Issue
Block a user