The Subspace C++ Library

The Subspace C++ Library provides a concept-centered abstraction on top of the bare-metal C++ standard library. It provides the tools to build stable applications quickly, and to make your application performant through explicitly leveraging compiler optimizations without accidentally tripping over Undefined Behaviour and miscompilation. Stop spending time debugging tricky heisenbugs and start relying on the compiler to produce the program you wrote.

Find Subspace on Github here: https://github.com/chromium/subspace

Prelude

The sus/prelude.h header imports the most commonly used types into the global namespace. All types in the prelude namespace are included:

Example

#include "sus/prelude.h"

int main() {
    auto v = Vec<i32>(1, 2, 3, 4, 5);
    return sus::move(v).into_iter().sum();
}

Namespaces

  • sus

    The root namespace of the Subspace C++ library.

  • Checking for (e.g. sus_check) and handling (e.g. sus_panic, sus_unreachable) unexpected runtime conditions.

  • The Box<T> type for heap allocation and other tools for type-erasure of concepts.

  • The Choice type.

  • cmp

    Utilities for comparing and ordering values.

  • Collection types.

  • Concepts and functions for constructing and converting between types.

  • env

    Inspection and manipulation of the process's environment.

  • Interfaces for working with Errors.

  • fn

    The Fn, FnMut and FnOnce concepts for working with functors and callable types.

  • Composable external iteration.

  • Marker types, such as for accessing unsafe APIs, for overload resolution, or type elision.

  • mem
  • num

    Safe integer (e.g. i32) and floating point (e.g. f32) numerics, and numeric concepts.

  • ops
  • The Option type, and the some and none type-deduction constructor functions.

  • Commonly used things that can be pulled into the global top level namespace. This is done by default when including the sus/prelude.h header.

  • ptr
  • The Result type, and the ok and err type-deduction constructor functions.

  • The Tuple type, and the tuple type-deduction constructor function.

Operators

Type Aliases

  • A collection of objects of type T, with a fixed size N.

  • The Option type.

  • A dynamically-sized const view into a contiguous sequence of objects of type const T.

  • A resizeable contiguous buffer of type T.

  • A 32-bit floating point type.

  • A 64-bit floating point type.

  • A 16-bit signed integer.

  • A 32-bit signed integer.

  • A 64-bit signed integer.

  • An 8-bit signed integer.

  • An address-sized signed integer.

  • A 16-bit unsigned integer.

  • A 32-bit unsigned integer.

  • A 64-bit unsigned integer.

  • An 8-bit unsigned integer.

  • A pointer-sized unsigned integer.

  • An address-sized unsigned integer.

Variable Aliases

Macros

  • A macro that replaces the INFINITY macro from the <cmath> header. Consider using f32::INFINITY instead.

  • A macro that replaces the NAN macro from the <cmath> header. Consider using f32::NAN instead.

  • Verifies that the input, evaluated to a bool, is true. Otherwise, it will panic, printing a message and terminating the program.

  • Verifies that the input cond, evaluated to a bool, is true. Otherwise, it will panic, printing a customized message, and terminating the program.

  • A macro used to declare the value-type pairings in a Choice. See the Choice type for examples of its use.

  • Mark a class field as never being a specific value, often a zero, after a constructor has run and before the destructor has completed. This allows querying if a class is constructed in a memory location, since the class is constructed iff the value of the field is not the never-value.

  • Mark a class as unconditionally trivially relocatable while also asserting that all of the types passed as arguments are also marked as such.

  • Mark a class as trivially relocatable based on a compile-time condition.

  • Mark a class as trivially relocatable if the types passed as arguments are all trivially relocatable.

  • Mark a class as unconditionally trivially relocatable, without any additional assertion to help verify correctness.

  • Check a condition in debug builds, causing a sus_panic() if the condition fails. Nothing is checked in release builds.

  • Macro to help implement DynC for a concept C. The macro is placed in the body of the DynC class.

  • Macro to help implement DynCTyped for a concept C. The macro is placed in the body of the DynCTyped class.

  • Terminate the program.

  • Terminate the program, after printing a message.

  • Indicates to the developer that the location should not be reached, and terminates the program with a panic.

  • Indicates to the compiler that the location will never be reached, allowing it to optimize code generation accordingly. If this function is actually reached, Undefined Behaviour will occur.