<xstd/bits/bit_set/bit_key_mapping.hpp>¶
bit_key_mapping, bit_range_mapping, bit_find_mapping, enum_traits¶
template<class Key, Key First, size_t N>
requires see below
struct bit_range_mapping {
static constexpr size_t size = N;
static constexpr auto is_key(Key key) noexcept -> bool;
static constexpr auto to_index(Key key) noexcept -> size_t;
static constexpr auto from_index(size_t index) noexcept -> Key;
};
template<class Key, const auto& Keys>
requires see below
struct bit_find_mapping {
static constexpr size_t size = ranges::size(Keys);
static constexpr auto is_key(Key key) noexcept -> bool;
static constexpr auto to_index(Key key) noexcept -> size_t;
static constexpr auto from_index(size_t index) noexcept -> Key;
};
A key's mapping is an order-preserving bijection onto the positions 0 to size - 1: a < b exactly where
to_index(a) < to_index(b), and from_index inverts to_index.
bit_range_mapping<Key, First, N>maps theNconsecutive keys fromFirst, of an integer or an enumeration, onto0toN - 1.is_key(k)holds forFirst <= k < First + N, compared as an unsigned distance fromFirst, so no bound overflowsKey. A key outside the range ranks atNor above.bit_find_mapping<Key, Keys>maps each key of the listKeysto its rank there, found by binary search, so a gap costs no position. Mandates:Keysascends strictly.is_key(k)holds for a listed key, and any other ranks atsize.bit_key_mapping<Key>is the mapping a set takes by default. Its primary template is declared and not defined, and it is specialized aschar_traitsis:- for every unsigned integer
Key, the identity, with nosize, leaving the universe open;is_key(k)holds whereksurvives the round trip throughsize_t; - for an enumeration whose
enum_traits<Key>::valuesis declared,bit_range_mappingwhere the values run without a gap andbit_find_mappingover the list otherwise; - for an enumeration that declares no list and has an enumerator
count,bit_range_mappingfromKey{}tocount, the sentinel itself no key. Mandates:countis not negative. - A program may specialize it for a key type of its own, such as a strong index.
- for every unsigned integer
enum_traits<Enum>is empty. A program specializes it beside an enumeration with astatic constexprstd::arraynamedvalues, listing the enumerators ascending, each once.