Essentials

common.h

Fundamental concepts, numeric limits, hashes, index ranges, and output helpers.

C++23 mc/common.h
#include <mc/common.h>

CInteger excludes bool; CFloat includes half. Collection concepts classify Catalyst container families.

cspan iterates numeric indices in a half-open interval. It is distinct from an element view such as CArrayBuf.

Jump to a declaration · 130

Free functions & types

Types, constants & data

using chash128 = __uint128_t;
using chash64 = uint64_t;
using chash = chash128;
using chash_ref = chash;
using half = _Float16;
using CContainerSize = uint32_t;
using CBufferHeapId = uint32_t;
constexpr size_t CKilobyte = 1024;
constexpr size_t CMegabyte = CKilobyte * CKilobyte;
constexpr size_t CGigabyte = CMegabyte * CKilobyte;
template<class T, class S> concept CSame = std::same_as<std::remove_cvref_t<T>, S>;
template<class T, class S> concept CConvertible = std::is_convertible_v<T, S>;
template<class I> concept CInputIterator = std::input_iterator<I> || requires{ typename std::iterator_traits<I>::iterator_category; requires std::derived_from<typename std::iterator_traits<I>::iterator_category, std::input_iterator_tag>; };
template<class R, class T> concept CContainerRange = std::ranges::input_range<R> && std::convertible_to<std::ranges::range_reference_t<R>, T>;
template<class T> concept CTransparent = requires{ typename T::is_transparent; };
template<class T> concept CAllocator = requires(T& allocator, size_t size){ typename T::value_type; allocator.allocate(size); };
template<class T> concept CInteger = (std::is_integral_v<std::remove_cvref_t<T>> || CSame<T, chash>) && !CSame<T, bool>;
template<class T> concept CFloat = std::is_floating_point_v<std::remove_cvref_t<T>> || CSame<T, half>;
template<class T> concept CNumeric = CInteger<T> || CFloat<T>;
template<class T> concept CArithmetic = CInteger<T> || CFloat<T> || CSame<T, bool>;
template<class T> concept CString = CSame<T, cstr> || CSame<T, std::string> || CConvertible<T, const char*>;
template<class T> concept CSequence = CIsSequence_<std::remove_cvref_t<T>>::value;
template<class T> concept CAnySet = CIsSet_<std::remove_cvref_t<T>>::value;
template<class T> concept CItems = CSequence<T> || CAnySet<T>;
template<class T> concept CAnyMap = CIsMap_<std::remove_cvref_t<T>>::value;
template<class T> concept CLockable = requires(T v){ v.lock(); v.unlock(); };
template<class T> concept CReadLockable = requires(T v){ v.readLock(); v.readUnlock(); };
template<class T> concept CWriteLockable = requires(T v){ v.writeLock(); v.writeUnlock(); };
template<class T> concept CStorable = requires(CBuffer& b, const std::remove_cvref_t<T>& v){ std::remove_cvref_t<T>(b); v.store(b); };
template<class T> concept CHashable = requires(const T v){ v.hash(); };
template <typename T> constexpr bool CIsTuple = false;
template<typename... Types> constexpr bool CIsTuple<std::tuple<Types...>> = true;
constexpr bool COutputComma = false;
using cspan = cspan_<size_t>;
template<CNumeric T> inline constexpr T CMin = std::numeric_limits<T>::lowest();
template<> inline constexpr half CMin<half> = -__FLT16_MAX__;
template<CNumeric T> inline constexpr T CMax = std::numeric_limits<T>::max();
template<> inline constexpr half CMax<half> = __FLT16_MAX__;
template<CFloat T> inline constexpr T CInf = std::numeric_limits<T>::infinity();
template<CFloat T> inline constexpr T CNan = std::numeric_limits<T>::quiet_NaN();

Functions

operator<<

inline std::ostream& operator<<(std::ostream& ostr, half v);
inline std::ostream& operator<<(std::ostream& ostr, const chash& h);
template<class S, class T> inline std::ostream& operator<<(std::ostream& ostr, const std::pair<S, T>& p);
template<typename... T> inline std::ostream& operator<<(std::ostream& out, const std::tuple<T...>& t);
template<CAnyMap T> inline std::ostream& operator<<(std::ostream& ostr, const T& m);

cToHash

inline chash cToHash(uint64_t h1, uint64_t h2);

Combines two 64-bit words into a chash. Use cFromHash() to recover the pair.

cFromHash

inline std::pair<uint64_t, uint64_t> cFromHash(chash h);

Splits a chash into its two 64-bit words in the same order accepted by cToHash().

cOutputTuple_

template<typename... T, size_t... Indices> inline std::ostream& cOutputTuple_(std::ostream& out, const std::tuple<T...>& t, std::index_sequence<Indices...>);

Writes tuple elements to a stream using the supplied index sequence. This supports the tuple stream formatter.

cOutputSequence

template<class T> inline void cOutputSequence(std::ostream& ostr, const T& v);

Writes a sequence with brackets and the configured element separator, using each element’s stream formatter.

cOutputMap_

template<class T> inline void cOutputMap_(std::ostream& ostr, const T& m);

Writes map entries using the framework’s configured key/value and element separators.

cOutputMap

template<CAnyMap T> inline void cOutputMap(std::ostream& ostr, const T& m);

Writes a map with braces and key/value separators, using each key and value’s stream formatter.

cOutputOrderedSet

template<class T> inline void cOutputOrderedSet(std::ostream& ostr, const T& s);

Writes a set in its iteration order using the Catalyst set display format.

cPrint

template<CString T> void cPrint(T&& msg);
template<class T> void cPrint(T&& x);

Writes a value followed by a newline and flushes standard output. Catalyst output calls share an output lock.

cOut

template<CString T> void cOut(T&& msg);
template<class T> void cOut(T&& x);

Writes a value without adding a newline.

cSpan_

template<CInteger I> cspan_<I> cSpan_(I i);
template<class T> requires(!std::is_integral_v<T>) auto cSpan_(const T& v);
template<CInteger I> cspan_<I>&& cSpan_(cspan_<I>&& s);

Adapts an integer count to [0,count), forwards a collection’s span(), or passes through an existing numeric span. Used by generated numeric iteration code.

cSecs

inline auto cSecs(double secs);

Converts a floating-point number of seconds to a duration stored in whole microseconds. Fractional microseconds are truncated.

cRequiredBytes

inline int cRequiredBytes(int64_t i);

Returns the legacy signed-integer encoding width code: 0 for values from 0 through 127, otherwise 1, 2, 4, or 8. The zero code is special and should not be treated as an ordinary allocation size.

cReadTuple__

template<size_t J, class S, class... Ts> void cReadTuple__(const std::tuple<Ts...>& t, S& s);

Legacy tuple-to-sequence helper. Its current template forwarding is incomplete and should not be used for general tuple conversion; prefer a container’s fromTuple() where available.

cMin

template<CNumeric T> void cMin(T& x);

Assigns the lowest representable numeric value to x. This is an initializer for minimum bounds, not a two-value comparison.

cMax

template<CNumeric T> void cMax(T& x);

Assigns the largest representable numeric value to x.

cDispatch_

template<CHashable T> chash_ref cDispatch_(const T& x);
template<class T> T cDispatch_(const T& x);

Selects a value’s hash() for hashable dispatch operands and otherwise returns the operand value. Used by generated dispatch expressions.

cIdx_

template<size_t I, class T> decltype(auto) cIdx_(T&& x);
template<size_t I, class... Ts> decltype(auto) cIdx_(const std::tuple<Ts...>& t);
template<size_t I, class... Ts> decltype(auto) cIdx_(std::tuple<Ts...>& t);
template<size_t I, class S, class T> decltype(auto) cIdx_(const std::pair<S, T>& t);
template<size_t I, class S, class T> decltype(auto) cIdx_(std::pair<S, T>& t);

Selects a compile-time index from a tuple, pair, or indexable value. Preserves the selected element’s reference category for binding and assignment.

CIsSequence_

template<class T> struct CIsSequence_ : std::false_type
template<class T, class Alloc> struct CIsSequence_<CVector<T, Alloc>> : std::true_type
template<class T, uint32_t N> struct CIsSequence_<CSVector<T, N>> : std::true_type
template<class T, class Alloc> struct CIsSequence_<CList<T, Alloc>> : std::true_type
template<class T, class Alloc> struct CIsSequence_<CDeque<T, Alloc>> : std::true_type
template<class T, class Alloc> struct CIsSequence_<CVectorSet<T, Alloc>> : std::true_type
template<class T, size_t Extent> struct CIsSequence_<CArrayBuf<T, Extent>> : std::true_type

CIsSet_

template<class T> struct CIsSet_ : std::false_type
template<class K, class Cmp, class Alloc> struct CIsSet_<CSet<K, Cmp, Alloc>> : std::true_type
template<class K, class Cmp, class Alloc> struct CIsSet_<CFlatSet<K, Cmp, Alloc>> : std::true_type
template<class K, class Hash, class Equal, class Alloc> struct CIsSet_<CHashSet<K, Hash, Equal, Alloc>> : std::true_type
template<class T, class Alloc> struct CIsSet_<CVectorSet<T, Alloc>> : std::true_type

CIsMap_

template<class T> struct CIsMap_ : std::false_type
template<class K, class V, class Cmp, class Alloc> struct CIsMap_<CMap<K, V, Cmp, Alloc>> : std::true_type
template<class K, class V, class Cmp, class Container, class MappedContainer> struct CIsMap_<CFlatMap<K, V, Cmp, Container, MappedContainer>> : std::true_type
template<class K, class V, class Hash, class Equal, class Alloc> struct CIsMap_<CHashMap<K, V, Hash, Equal, Alloc>> : std::true_type

cspan_

template<CInteger T> class cspan_

Methods

cspan_

template<CInteger S> constexpr cspan_(T begin, S end);
constexpr cspan_(T end);

Creates a numeric range [begin, end), or [0, end). Iteration increments by one; supply an ordered interval so iteration can reach the end.

begin

constexpr iterator_ begin();

end

constexpr iterator_ end();

cspan_::iterator_

class iterator_

Methods

operator!=

constexpr bool operator!=(const iterator_& itr) const;

CReadTuple__

template<size_t I, size_t J, class T> struct CReadTuple__

Methods

get

template<class S> static size_t get(const T& t, S& s);

Intended to copy tuple elements into a destination sequence starting at offset J. Current limitation: the recursive branch is incomplete and cannot be relied on for multi-element tuples.

CToken

struct CToken

Types, constants & data

static constexpr uint64_t Symbol = 0;
static constexpr uint64_t Operator = 1;
static constexpr uint64_t String = 2;
static constexpr uint64_t Function = 3;
static constexpr uint64_t Comment = 4;
static constexpr uint64_t Struct = 5;
static constexpr uint64_t Type = 6;
static constexpr uint64_t Include = 7;
static constexpr uint64_t Keyword = 8;
static constexpr uint64_t Numeric = 9;
static constexpr uint64_t Variable = 10;
static constexpr uint64_t Call = 11;
static constexpr uint64_t Preprocessor = 12;
static constexpr uint64_t Char = 13;
static constexpr uint64_t Key = 14;
static constexpr uint64_t None = 15;
static constexpr uint64_t Foreground0 = 30;
static constexpr uint64_t Foreground1 = 31;
static constexpr uint64_t Foreground2 = 32;
static constexpr uint64_t Foreground3 = 33;
static constexpr uint64_t Foreground4 = 34;
static constexpr uint64_t Foreground5 = 35;
static constexpr uint64_t Foreground6 = 36;
static constexpr uint64_t Foreground7 = 37;
static constexpr uint64_t Background0 = 40;
static constexpr uint64_t Background1 = 41;
static constexpr uint64_t Background2 = 42;
static constexpr uint64_t Background3 = 43;
static constexpr uint64_t Background4 = 44;
static constexpr uint64_t Background5 = 45;
static constexpr uint64_t Background6 = 46;
static constexpr uint64_t Background7 = 47;
uint64_t type : 8;
uint64_t index : 24;
uint64_t size : 16;
uint64_t bold : 1 = 0;
uint64_t faint : 1 = 0;
uint64_t underlined : 1 = 0;

Methods

CToken

CToken();
CToken(uint64_t type, uint64_t index, uint64_t size);

Stores a token kind, byte index, and byte length in the compact token representation. The default constructor does not initialize these fields.

CDelegated

template<class Delegate> class CDelegated

Methods

CDelegated

CDelegated();
CDelegated(Delegate* delegate);

Stores a borrowed delegate pointer, initially null if omitted. The delegate must remain alive while this object uses it.

delegate

Delegate* delegate() const;

Returns the current borrowed delegate, which may be null.

setDelegate

void setDelegate(Delegate* delegate);

Replaces the borrowed delegate pointer without deleting either delegate. This helper supplies no synchronization for concurrent access.

CRelease

template<class T> class CRelease

Methods

CRelease

CRelease(T& t);
CRelease(const CRelease&) = delete;

Arranges to call release() on the referenced object at scope exit. It does not acquire the resource; the object must already be in a releasable state and outlive the guard.

~CRelease

~CRelease();

Calls release() on the referenced object. The release operation must not allow an exception to escape destruction.

CTStr

template<size_t N> struct CTStr

Types, constants & data

std::array<char, N> str;

Methods

CTStr

constexpr CTStr(const char (&s)[N]);

Copies a string literal, including its terminator, into a fixed-size compile-time string suitable for template parameters.

operator==

template<size_t M> constexpr bool operator==(const char (&s)[M]);
template<size_t M> constexpr bool operator==(const CTStr<M>& s);

operator!=

template<size_t M> constexpr bool operator!=(const char (&s)[M]);
template<size_t M> constexpr bool operator!=(const CTStr<M>& s);

std::hash

template<class A, class B> struct hash<pair<A, B>>

Methods

operator()

size_t operator()(const pair<A, B>& p) const;

Free functions & types

Types, constants & data

#define handlers
#define executors
#define np(X)
#define npe(X)