https://github.com/isc30/generic_optional
enables reference types for std::optional
https://github.com/isc30/generic_optional
cpp optional
Last synced: 11 months ago
JSON representation
enables reference types for std::optional
- Host: GitHub
- URL: https://github.com/isc30/generic_optional
- Owner: isc30
- Created: 2018-07-26T22:36:36.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-08-24T08:23:59.000Z (over 7 years ago)
- Last Synced: 2025-01-18T02:43:55.466Z (about 1 year ago)
- Topics: cpp, optional
- Language: C++
- Homepage:
- Size: 8.79 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# generic_optional<T>
Compile-time wrapper over `std::optional` that enables optional reference types.
### How it works
For non-reference types:
- `generic_optional` → (deduces to) → `optional`
For reference types:
- `generic_optional` → (deduces to) → `optional>`
### Usage
Use `generic_optional` instead of `optional` in the declaration.
### Example
```cpp
generic_optional number;
generic_optional number_cref;
int test_value = 33;
number = test_value;
number_cref = test_value;
test_value = 111;
assert(number == 33);
assert(number_cref == 111);
```