cheatah
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 once
5/**
6 * @file mode.hpp
7 * @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 user
11 * spells them `memory.read` / `memory.write`.
12 */
14#include <type_traits>
16namespace cheatah::memory {
18struct read {}; ///< a shared, read-only lease (readers coexist — `std::shared_lock`-flavored, but no lock object is held).
19struct write {}; ///< an exclusive, one-shot write lease (a writer is alone — `std::unique_lock`-flavored, but no lock object is held).
20struct 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 tags
23/// (per the project's constrain-all-templates policy).
24template <class M>
25concept 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.
28template <class M>
29inline constexpr bool is_write_mode = std::is_same_v<M, write> || std::is_same_v<M, write_renewable>;
31} // namespace cheatah::memory