🟩 Primitive types, asserts, limits, Function, Span, Result
Foundation library provides many fundamental type definitions and types widely used by other libraries.
As this is included and needed by almost every other library, it tries to keep bloat to the bare minimum.
Detailed documentation is in the Foundation topic.
Class | Description |
---|---|
SC::Span | View over a contiguous sequence of items (pointer + size in elements). |
SC::StringViewData | An read-only view over a string (to avoid including Strings library when parsing is not needed). |
SC::Result | An ascii string used as boolean result. SC_TRY macro forwards errors to caller. |
SC::Function | Wraps function pointers, member functions and lambdas without ever allocating. |
SC::Deferred | Executes a function at end of current scope (in the spirit of Zig defer keyword). |
SC::OpaqueObject | Hides implementation details from public headers (static PIMPL). |
SC::UniqueHandle | Move only handle that has a special tag value flagging its invalid state. |
Compiler Macros Preprocessor macros to detect compiler and platform features.
Type Traits (EnableIf, AddPointer, RemovePointer, etc.)
Class | Description |
---|---|
SC::Assert | Functions and macros to assert, exit() or abort() and capture backtraces. |
SC::AlignedStorage | A buffer of bytes with given alignment. |
SC::MaxValue | An object that can be converted to any primitive type providing its max value. |
🟩 Usable
The library is very simple it it has what is needed so far by the other libraries.
There is an hard rule in the library Principles not to include system and compiler headers in public headers.
Foundation provides all primitive types to be used in headers and classes like SC::UniqueHandle, SC::OpaqueObject, SC::AlignedStorage to encourage static PIMPL in order to hide platform specific implementation details everywhere.
Wraps function pointers, member functions and lambdas without ever allocating.
FuncType | Type of function to be wrapped (Lambda, free function or pointer to member function) |
2 * sizeof(void*)
). LAMBDA_SIZE
the constructor will static assert.Example:
Executes a function at end of current scope (in the spirit of Zig defer
keyword).
F | The lambda / function to execute |
Example:
Hides implementation details from public headers (static PIMPL).
Opaque object avoids the heap allocation that often comes with PIMPL, allowing to hide OS specific details from public headers. User declares size in bytes of a struct in the header but the structure can be defined in an implementation .cpp file. Choosing a size that is too small will generate a static_assert
that contains in the error message the minimum size to use. Up to 4 functions will need to be defined to avoid linker errors (construct
, destruct
, moveConstruct
, moveAssign
). These functions are meant to be defined in a .cpp
file that will know how to construct Object, as it can see its definition.
Definition | Pass in a custom Definition declaring Sizes and alignment on different platforms |
Example:
Move only handle that has a special tag value flagging its invalid state.
Typically used to wrap Operating System specific handles.
Definition | A struct declaring handle type, release function and invalid handle value. |
Example:
Some relevant blog posts are:
🟦 Complete Features: