Restructure into umbrella modules (~55 -> 16 targets)
Headers move, CMake targets merge, C++ namespaces stay unchanged: - Core: Scope, Lazy, Counted, Flags, Hash, Bits, Uuid, TypeList, TypeMap, Variant - Functional: Pipeline, Either, Result, Retry - Containers: Ring, Pool, PriorityQueue, LRU, Trie, Graph, DisjointSet, Bitset, Interval - Math: +Matrix, Numeric, Random, Histogram - Text: Str, Format, Tokenizer, Diff, Encoding, Semver - Data: Json, Csv, Ini - Async: Coro, Concurrency, EventBus, Observable - Time: +Bench - Log: Log facade + Logging framework (facade now header-only, breaking the Stacktrace<->Log link cycle the merge would have created) - System: FileSystem + Process - Configuration: +Argparse - Unchanged: Stacktrace, Plugin, StateMachine, Testing, TestingMock, Detail Module system fixes: - OPTIONAL_DEPS resolution deferred to void_finalize_modules() so it no longer depends on the alphabetical discovery order of src/ subdirs (Testing -> Text would have been silently dropped). - Every header-only module now has a tracked module.cmake; previously the empty src/<Name> marker dirs were untracked, so a fresh clone would have silently skipped those modules. - VOID_HAS_LOGGING/CONCURRENCY/STR consumers renamed to LOG/ASYNC/TEXT. Tests move to tests/standalone/<Umbrella>/<Feature>.cpp (Result suite files prefixed: ResultBasic etc.). Test count verified identical (831) before and after. README/CLAUDE.md module tables updated. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
da2e93c405
commit
28b94883fd
156 files changed
+278
-220
No files matched your search
@@ -0,0 +1,114 @@
|
||||
#pragma once
|
||||
|
||||
#include <initializer_list>
|
||||
#include <type_traits>
|
||||
|
||||
namespace Void::Flags
|
||||
{
|
||||
|
||||
// ── Flags<E> ─────────────────────────────────────────────────────────────────
|
||||
// Type-safe bitmask wrapper over a scoped enum class E.
|
||||
// E's enumerators must be distinct single-bit values (1, 2, 4, 8, …).
|
||||
|
||||
template <typename E>
|
||||
requires std::is_enum_v<E>
|
||||
class Flags
|
||||
{
|
||||
public:
|
||||
using underlying = std::underlying_type_t<E>;
|
||||
|
||||
constexpr Flags() noexcept = default;
|
||||
constexpr Flags(E bit) noexcept : bits_{static_cast<underlying>(bit)} {}
|
||||
constexpr explicit Flags(underlying raw) noexcept : bits_{raw} {}
|
||||
constexpr Flags(std::initializer_list<E> list) noexcept
|
||||
{
|
||||
for (const E e : list) bits_ |= static_cast<underlying>(e);
|
||||
}
|
||||
|
||||
// ── query ─────────────────────────────────────────────────────────────────
|
||||
|
||||
[[nodiscard]] constexpr bool test(E bit) const noexcept
|
||||
{
|
||||
return (bits_ & static_cast<underlying>(bit)) != 0;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr bool any() const noexcept { return bits_ != 0; }
|
||||
[[nodiscard]] constexpr bool none() const noexcept { return bits_ == 0; }
|
||||
|
||||
[[nodiscard]] constexpr bool all(Flags mask) const noexcept
|
||||
{
|
||||
return (bits_ & mask.bits_) == mask.bits_;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr bool any_of(Flags mask) const noexcept
|
||||
{
|
||||
return (bits_ & mask.bits_) != 0;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr underlying raw() const noexcept { return bits_; }
|
||||
|
||||
// ── mutation ──────────────────────────────────────────────────────────────
|
||||
|
||||
constexpr Flags& set(E bit) noexcept
|
||||
{
|
||||
bits_ |= static_cast<underlying>(bit);
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Flags& unset(E bit) noexcept
|
||||
{
|
||||
bits_ &= ~static_cast<underlying>(bit);
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Flags& toggle(E bit) noexcept
|
||||
{
|
||||
bits_ ^= static_cast<underlying>(bit);
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr void clear() noexcept { bits_ = 0; }
|
||||
|
||||
// ── operators ─────────────────────────────────────────────────────────────
|
||||
|
||||
[[nodiscard]] constexpr Flags operator|(Flags o) const noexcept { return Flags{static_cast<underlying>(bits_ | o.bits_)}; }
|
||||
[[nodiscard]] constexpr Flags operator&(Flags o) const noexcept { return Flags{static_cast<underlying>(bits_ & o.bits_)}; }
|
||||
[[nodiscard]] constexpr Flags operator^(Flags o) const noexcept { return Flags{static_cast<underlying>(bits_ ^ o.bits_)}; }
|
||||
[[nodiscard]] constexpr Flags operator~() const noexcept { return Flags{static_cast<underlying>(~bits_)}; }
|
||||
|
||||
[[nodiscard]] constexpr Flags operator|(E bit) const noexcept { return *this | Flags{bit}; }
|
||||
[[nodiscard]] constexpr Flags operator&(E bit) const noexcept { return *this & Flags{bit}; }
|
||||
[[nodiscard]] constexpr Flags operator^(E bit) const noexcept { return *this ^ Flags{bit}; }
|
||||
|
||||
constexpr Flags& operator|=(Flags o) noexcept { bits_ |= o.bits_; return *this; }
|
||||
constexpr Flags& operator&=(Flags o) noexcept { bits_ &= o.bits_; return *this; }
|
||||
constexpr Flags& operator^=(Flags o) noexcept { bits_ ^= o.bits_; return *this; }
|
||||
|
||||
constexpr Flags& operator|=(E bit) noexcept { return set(bit); }
|
||||
constexpr Flags& operator&=(E bit) noexcept { bits_ &= static_cast<underlying>(bit); return *this; }
|
||||
constexpr Flags& operator^=(E bit) noexcept { return toggle(bit); }
|
||||
|
||||
[[nodiscard]] constexpr bool operator==(const Flags&) const noexcept = default;
|
||||
[[nodiscard]] constexpr explicit operator bool() const noexcept { return any(); }
|
||||
|
||||
private:
|
||||
underlying bits_{0};
|
||||
};
|
||||
|
||||
// ── make_flags — convenience factory ─────────────────────────────────────────
|
||||
|
||||
template <typename E>
|
||||
requires std::is_enum_v<E>
|
||||
[[nodiscard]] constexpr Flags<E> make_flags(std::initializer_list<E> list) noexcept
|
||||
{
|
||||
return Flags<E>{list};
|
||||
}
|
||||
|
||||
template <typename E>
|
||||
requires std::is_enum_v<E>
|
||||
[[nodiscard]] constexpr Flags<E> operator|(E a, E b) noexcept
|
||||
{
|
||||
return Flags<E>{a} | Flags<E>{b};
|
||||
}
|
||||
|
||||
} // namespace Void::Flags
|
||||
Reference in new issue
Block a user