Skip to content
@z-libs

z-libs

z-libs: Modern single-header libraries for C/C++

Sponsor

Zero-dependency • Header-only • C11 - C++11/C++17 • Type-safe • Lua Bindings

z-libs is a collection of single-header container libraries. They are written in pure C for maximum portability but include zero-cost C++ wrappers for modern developer ergonomics.

These libraries allow you to write standard C11 code with full control over memory, drop them into a C++ project to utilize RAII and range-based loops, or expose them to scripting languages like Lua without performance loss.

The "Bridge" Philosophy

Most libraries force you to choose a side. z-libs lets you cross the border freely.

1. Works perfectly in C11: Full control, no hidden allocations, type-safe macros.

// zvec: Dynamic Arrays
vec(int) scores = vec_init(int);
vec_push(&scores, 10);

// zstr: SSO Strings
zstr name = zstr_lit("Ada");
zstr_fmt(&name, " %s", "Lovelace");

// zmap: Hash Maps
map(ages) ages = map_init(ages);
map_put(&ages, "Grace", 85);

2. And the SAME headers work natively in C++: RAII, methods, iterators, and std:: compatibility.

// z_vec: Wrapper around vec_int
z_vec::vector<int> scores = {10, 42};

// z_map: Wrapper around map_ages
z_map::map<std::string, int> ages;
ages.put("Grace", 85);

// z_str: Wrapper around zstr
z_str::string name = "Ada";
for (auto part : name.split(" "))
{
    std::cout << part << "\n";
}

3. Scripting Ready (Lua): High-performance mutable buffers for scripts to avoid garbage collection churn.

local zstr = require("zstr")
local buf = zstr.new("Start: ")

-- Efficient appending (no intermediate garbage).
buf:append("User=", "Alice", " ID=", tostring(101))
buf:upper()

print(tostring(buf)) -- "START: USER=ALICE ID=101"

The Libraries

Library Description Features Status
zvec Type-safe dynamic arrays Full C++ Wrapper Stable
zstr SSO-optimized strings & views C++ Wrapper, Lua Bindings Stable
zmap Open-addressing hash maps Full C++ Wrapper Stable
zlist Doubly-linked lists Full C++ Wrapper Stable
zalloc Arenas, Pools, and Leak Detection Zero-overhead, Cache-friendly Stable

Quick Start

The libraries are designed to be modular. You can grab just one, or use them all together.

Option A: The Suite (Recommended)

Use z-core tools to manage type generation automatically.

git submodule add https://github.com/z-libs/zvec.h.git
git submodule add https://github.com/z-libs/zstr.h.git
git submodule add https://github.com/z-libs/z-core.git

Option B: Drag and Drop

Since they are header-only and zero-dependency, you can simply download zvec.h or zstr.h and drop them into your include/ folder.

Why z-libs?

Most C container libraries suffer from Macro Hell (cryptic errors), void* soup (no type safety), or Build System Fatigue (requiring CMake/Make just to use a vector).

z-libs solves this by using modern C11 features (_Generic) for the implementation while providing a "feels-like-native" C++ layer on top.

  • Zero external dependencies: Standard C library only.
  • Truly single-header: Just drop the file in your project.
  • Allocator-aware: Use zalloc.h (arenas, pools) or your custom heaps.
  • Universal: Compiles on GCC, Clang, MSVC, and tiny microcontrollers.

Meet Zibi

Zibi is the tiny green ogre that guards your memory.

He started life as a random GitHub identicon, reminded us of an ogre, and became the official mascot.

Zibi likes:

  • Single-header libraries.
  • Stack allocation (SSO).
  • Onions (because C macros have layers).

Zibi hates:

  • void* casting.
  • Segfaults.
  • Complex build scripts.

If your code compiles and runs on the first try, Zibi is happy.

Zibi

License

The whole project uses the MIT License.

Pinned Loading

  1. zvec.h zvec.h Public

    A type-safe, header-only generic vector library for C/C++ using X-Macros.

    C++ 31 2

  2. zlist.h zlist.h Public

    A type-safe, header-only generic doubly linked list library for C/C++ using X-Macros.

    C++ 23 3

  3. zstr.h zstr.h Public

    A modern, header-only string library for C/C++ using Small String Optimization (SSO) and Views.

    C 19 5

  4. zmap.h zmap.h Public

    A type-safe, header-only generic map library for C/C++ using X-Macros.

    C 23 2

  5. zrand.h zrand.h Public

    A statistically robust, header-only PCG random number library for C/C++.

    C++ 1

Repositories

Showing 10 of 17 repositories
  • znet.h Public

    A cross-platform, header-only networking library for C/C++ that unifies TCP, UDP, and HTTP under a single, simple API.

    z-libs/znet.h’s past year of commit activity
    C 0 MIT 0 0 0 Updated Dec 17, 2025
  • zwasm.h Public

    A freestanding, header-only WebAssembly binary generator for C/C++ without external dependencies.

    z-libs/zwasm.h’s past year of commit activity
    C 1 MIT 0 0 0 Updated Dec 17, 2025
  • zfile.h Public

    A cross-platform, header-only file system library for C/C++ that simplifies path manipulation, file I/O, and directory traversal.

    z-libs/zfile.h’s past year of commit activity
    C++ 1 MIT 0 0 0 Updated Dec 17, 2025
  • zdk Public

    The Zen Development Kit

    z-libs/zdk’s past year of commit activity
    C++ 36 MIT 2 0 0 Updated Dec 17, 2025
  • zmath.h Public

    A zero-dependency, header-only math library for C/C++ using deterministic software approximations.

    z-libs/zmath.h’s past year of commit activity
    C 2 MIT 0 0 0 Updated Dec 17, 2025
  • zstr.h Public

    A modern, header-only string library for C/C++ using Small String Optimization (SSO) and Views.

    z-libs/zstr.h’s past year of commit activity
    C 19 MIT 5 0 1 Updated Dec 17, 2025
  • zrand.h Public

    A statistically robust, header-only PCG random number library for C/C++.

    z-libs/zrand.h’s past year of commit activity
    C++ 1 MIT 0 0 0 Updated Dec 17, 2025
  • zmap.h Public

    A type-safe, header-only generic map library for C/C++ using X-Macros.

    z-libs/zmap.h’s past year of commit activity
    C 23 MIT 2 0 0 Updated Dec 17, 2025
  • ztree.h Public

    A type-safe, header-only generic Red-Black tree library for C/C++ using X-Macros.

    z-libs/ztree.h’s past year of commit activity
    C++ 1 MIT 0 0 0 Updated Dec 16, 2025
  • zlist.h Public

    A type-safe, header-only generic doubly linked list library for C/C++ using X-Macros.

    z-libs/zlist.h’s past year of commit activity
    C++ 23 MIT 3 0 0 Updated Dec 16, 2025

Top languages

C++ C Python

Most used topics

Loading…