Update readme
This commit is contained in:
1 parent
717027db9b
commit
632bc4e1ad
1 file changed
+21
-1
@@ -1,5 +1,5 @@
|
|||||||
# optional
|
# 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)
|
Clang + GCC: [](https://travis-ci.org/TartanLlama/optional)
|
||||||
MSVC: [](https://ci.appveyor.com/project/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.
|
- `take`: returns the current value, leaving the optional empty.
|
||||||
* `opt_string.take().map(&std::string::size); //opt_string now 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
|
### Compiler support
|
||||||
|
|
||||||
Tested on:
|
Tested on:
|
||||||
|
|||||||
Reference in new issue
Block a user