| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | // This class acts like std::optional<std::span<T, N>>, but only stores a single |
| 8 | // pointer (which can be nullptr). A plain std::span<T, N> is not sufficient |
| 9 | // because it cannot represent an invalid state (nullptr). This class provides |
| 10 | // a lightweight way to optionally hold a fixed-size span without the overhead |
| 11 | // of std::optional. |
| 12 | // |
| 13 | // An alternative could be to use a plain pointer (T*). Though that doesn't give |
| 14 | // the guarantee that it points to N elements. This class enforces that on |
| 15 | // construction, and retains that information on usage. |
| 16 | // |
| 17 | // In the past we tried to use std::span<T, N> initialized with |
| 18 | // std::span<T, N>(static_cast<T*>(nullptr), N) |
| 19 | // That appeared to work, but it's actually undefined behavior. And with gcc |
| 20 | // debug STL mode it indeed triggers an error. |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | ; |
| 42 | |
| 43 | |