Source
stdlib/memory/mode.hpp
1
// Copyright (c) 2026 BigBrain LLC. MIT-licensed (see LICENSE).2
// Original work; see ACKNOWLEDGMENTS.md for the open-source ideas we build upon.3
#pragma once5
/**6
* @file mode.hpp7
* @brief `memory` access-mode tags: `read`, `write`, `write_renewable`, and the `Mode` concept.8
*9
* Empty tag types that select a `Lease`'s mode at compile time (dispatch on type, zero storage).10
* Lowercase because they are tags/markers, not classes (cf. `std::in_place_t`); a cheatah user11
* spells them `memory.read` / `memory.write`.12
*/14
#include <type_traits>16
namespace cheatah::memory {18
struct read {}; ///< a shared, read-only lease (readers coexist — `std::shared_lock`-flavored, but no lock object is held).19
struct write {}; ///< an exclusive, one-shot write lease (a writer is alone — `std::unique_lock`-flavored, but no lock object is held).20
struct write_renewable {}; ///< an exclusive write lease that MAY re-lease — a distinct, visible smell.22
/// The lease-mode concept — every `Lease`/`Request` template is constrained to one of the three tags23
/// (per the project's constrain-all-templates policy).24
template <class M>25
concept Mode = std::is_same_v<M, read> || std::is_same_v<M, write> || std::is_same_v<M, write_renewable>;27
/// True for the two exclusive (write) modes.28
template <class M>29
inline constexpr bool is_write_mode = std::is_same_v<M, write> || std::is_same_v<M, write_renewable>;31
} // namespace cheatah::memory