std1.0.0-beta-7 SafeC docs

Module cmp

#include <std/cmp.h> source

compile-time orderings

An ordering is a type with 'int cmp(const &T a, const &T b) const' returning <0, 0 or >0 — the Order trait below. Containers and algorithms take the ordering as a type parameter bounded by Order (BST<K, V, C: Order>, vec_sort_by(&v, ord)), so a type without cmp is rejected where it is named, and after monomorphization each comparison is a direct call the optimizer inlines — no function pointer, no per-compare indirect call. FnOrder<T> wraps a runtime function pointer for orderings only known at run time; any struct of your own with a cmp method is an Order too.

struct BST<int, int, Less<int>> t = std::BST::new();     // natural order, inlined
std::vec_sort_by(&v, std::FnOrder::of(by_name));         // runtime comparator

Structs

LessAscending by '<' / '>' (integers, floats, enums, pointers).
GreaterDescending.
FnOrderA comparator chosen at run time.

Traits

Order