Pixie
Loading...
Searching...
No Matches
element_storage.h
1#pragma once
2
4
5#include <concepts>
6#include <limits>
7#include <type_traits>
8
9namespace pixie::permutations::detail {
10
11// Resolve storage and read semantics once for the facade and its CRTP base.
12template <class T, ElementStorage Requested>
14 static_assert(std::is_object_v<T> && !std::is_array_v<T> &&
15 std::same_as<T, std::remove_cv_t<T>>);
16 static constexpr bool packable = std::is_integral_v<T> &&
17 std::is_unsigned_v<T> &&
18 std::numeric_limits<T>::digits <= 64;
19 static_assert(Requested == ElementStorage::automatic ||
20 Requested == ElementStorage::packed ||
21 Requested == ElementStorage::indirect);
22 static_assert(Requested != ElementStorage::packed || packable,
23 "Packed elements must be bool or unsigned integers <=64 bits");
24 static constexpr ElementStorage storage =
25 Requested == ElementStorage::automatic
26 ? (packable ? ElementStorage::packed : ElementStorage::indirect)
27 : Requested;
28 static constexpr bool packed = storage == ElementStorage::packed;
29 static_assert(
30 packed || (std::is_nothrow_move_constructible_v<T> &&
31 std::is_nothrow_destructible_v<T>),
32 "Indirect elements require noexcept move construction/destruction");
33 using const_reference = std::conditional_t<packed, T, const T&>;
34};
35
36} // namespace pixie::permutations::detail
Lightweight immutable-read permutable-sequence CRTP contract.
ElementStorage
Compile-time element storage selection.
Definition permutable_sequence.h:23