glouw/ctl logo

glouw/ctl

Free

The C Template Library

FreeFree tier
Type
Open Source

About glouw/ctl

CTL is a fast compiling, type safe, header only, template-like library for ISO C99/C11 that implements STL containers including deq (deque), lst (list), pqu (priority_queue), que (queue), set, stk (stack), str (string), ust (unordered_set), and vec (vector). It aims to improve developer productivity in C by providing familiar C++ STL-like interfaces with C99/C11 compliance. The library supports both plain old data (POD) types and user-defined types with memory ownership, and includes a foreach macro for iteration. Performance graphs and a test suite are available.

Key Features

Header-only library, no separate compilation step
Type safe using macros and compile-time checks
Fast compilation compared to C++ templates
ISO C99/C11 compliant
Implements std::deque, list, priority_queue, queue, set, stack, string, unordered_set, and vector
Memory ownership support for non-POD types (requires custom destructor and copy constructor)
Includes foreach macro for container iteration
Provides performance graphs and test suite

Pros & Cons

Pros
  • Header-only, easy to integrate (just include the ctl directory)
  • Type safety through C preprocessor macros and error messages
  • Fast compilation due to non-templated C macros
  • Comprehensive set of containers similar to C++ STL
  • Free and open source under a permissive license
  • Supports both POD and memory-managed types
Cons
  • Does not implement std::map (only sets are provided)
  • Does not support multi-containers (multi-set, multi-map) natively
  • String implementation does not support short string optimization
  • Requires manual memory management for non-POD types (no automatic destructor calls)

Best For

Embedded systems development where C is used and STL-like containers are neededTeaching C data structures and algorithms with a familiar interfacePorting C++ code to C while maintaining similar container semanticsGeneral C programming requiring dynamic containers (vector, string, set, etc.)

FAQ

What containers does CTL implement?
CTL implements deque, list, priority_queue, queue, set, stack, string, unordered_set, and vector, corresponding to C++ STL containers (deq.h, lst.h, pqu.h, que.h, set.h, stk.h, str.h, ust.h, vec.h).
Is CTL header-only?
Yes, CTL is a header-only library. To use it, include the ctl directory and the appropriate header file (e.g., #include vec.h).
Does CTL support custom types?
Yes, CTL supports both plain old data (POD) types and types with memory ownership. For POD types, define P and T. For non-POD types, provide type_free and type_copy functions before including the container header.
Does CTL implement std::map?
No, CTL does not implement std::map because the author considers maps to only provide slight syntactic improvements over sets.