zane-cpp is a small header-only C++20 helper library for writing C++ in a style that feels closer to the Zane language spec. Version 0.1.0 focuses on a tiny, polished surface instead of trying to emulate the whole language.
zane-cpp is currently aligned with a1921dd.
The pinned spec checkout lives in third_party/zane-spec/, and docs/design.md documents mappings and tradeoffs relative to that revision.
Under that spec revision, Zane structs are transitively value-only: they may contain primitives and other structs, but they must not contain classes or refs anywhere in their nested field graph. In this repository, zane::ref<T> examples therefore model Zane class-style storage or general C++ storage, not a Zane struct analogue.
zane::ref<T>for explicit non-owning, rebindable referenceszane::abortable<T, E>plusresolve,handle, andthenfor Zane-inspired bifurcated return flows without exceptionszane::pipe(...)for pipeline-style expression chainingzane::Array<N, T>andzane::array(...)for fixed-size array valueszane::unit/zane::void_valuefor payload-free success values
See docs/design.md for the full spec-to-C++ mapping, tradeoffs, and planned or rejected ideas.
The distributable header is:
#include <zane-cpp.hpp>The modular source root used to generate it is:
include-src/zane/prelude.hpp
#include <zane-cpp.hpp>
#include <string_view>
struct ParseError {
std::string_view message;
};
auto parse_scale(std::string_view text) -> zane::abortable<int, ParseError> {
if (text == "high") {
return zane::abortable<int, ParseError>::success(3);
}
return zane::abortable<int, ParseError>::abort({"expected \"high\""});
}
int main() {
auto value = parse_scale("low")
| zane::pipe([](auto result) {
return zane::handle(std::move(result), [](const ParseError&) {
return 0;
});
});
auto refs = zane::array(1, 2, 3);
return value + refs[0];
}A runnable example lives at examples/zane_like.cpp.
devbox run -- just build-headerExact Quom invocation:
devbox run -- python -m quom --include_directory include-src include-src/zane/prelude.hpp include/zane-cpp.hppdevbox run -- just testThe test suite compiles and runs two binaries:
- one against the modular root header from
include-src/ - one against the generated
include/zane-cpp.hppsingle header
devbox run -- just checkjust check rebuilds the single header, runs the tests, and compiles plus runs the example program.
include-src/zane/ modular headers
include/zane-cpp.hpp generated distributable header
tests/ offline-friendly test harness and coverage
examples/ example programs
docs/design.md spec-driven design notes and decisions
third_party/zane-spec pinned spec submodule