An open API service indexing awesome lists of open source software.

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

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);
```