bitwizeshift / bitwizeshift/bit-stl

Optimized `optional` type

Open
#3 0 comments 0 reactions 1 assignee Claimed by @bitwizeshift View on GitHub
enhancement
Dominant language
C++
Stars
9
Forks
0
PR merge metrics
No merged PRs in 30d

Description

C++17 introduces `optional` (of which, `bit::stl::optional` is based on for pre-c++17 support).

`optional` satisfies nullable stack values; however it does not play nice when used in composition, since the `bool` member pushes additional padding when used in arrays, or when a member immedately succeeds an `optional` member.

For this, there are two proposed types:
- `bit::stl::optional_array` -- an array of optional values that behaves like `std::array` where `value_type` is `T*` (with `nullptr` representing not-set). This would allow `N` optionals to be stored contiguously, with `N` `bool`s indicating their construction to also be contiguous.
- `bit::stl::optional_tuple` -- a `tuple` of values that may or may not contain a value. This is a generalization of `optional_array`, where each member may be a different type. The `bool`s indicating initialization is stored contiguously in memory, which optimizes storage.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.