Skip to content

Repository files navigation

SFC (Standard Foundation for C++)

License: GPL v3Language: C++23PlatformsNo STLPRs Welcome

A zero-STL, Rust-inspired foundational library for modern C++23 applications focused on safety, determinism, and performance – built from scratch so you control every byte.


Why SFC?

The C++ standard library is large, legacy-constrained, ABI-fragile, and sometimes unpredictable across platforms. Embedded, systems, tooling, game, and low-latency domains often need:

  • Deterministic behavior (no surprise allocations / hidden slow paths)
  • Tight binary size and no dependency on libstdc++ / MSVCPRT
  • Unified, expressive, ergonomic APIs (Rust-like Result, Option, ownership types)
  • Cross-platform primitives without #ifdef sprawl

SFC re-imagines the “stdlib” surface for C++23 with explicit design: minimal unsafe surface, predictable memory, and composable primitives.


✨ Feature Highlights

DomainWhat You GetNotes
Core TypesOption<T>, Result<T,E>, Tuple, Variant, iter utilitiesError handling & composition first
OwnershipBox<T>, Rc<T>Deterministic lifetimes, no STL smart ptrs
MemoryCustom allocator hooks, slices, raw pointer helpersFine-grained control
CollectionsList<T>, HashMap<K,V>, HashSet<T>, Queue<T>Purpose-built, STL-free
ConcurrencyMutex, Condvar, atomics, MPMC queue, threadsPortable & lean
TaskingLightweight async/task primitives (WIP)Foundation for schedulers
I/O & FSPaths, files, buffered stdio, platform bridgesUnified Windows / POSIX
TimeSteady + system clocks, duration typesClear conversions
LoggingPluggable backend-friendly logging coreMinimal formatting now, richer later
Ser/DeJSON, Base64Compile-time format checked
CLICommand-line argument parsing (clap)Structured arg definitions

🔍 Design Principles

  1. Zero STL dependency – everything is internally defined.
  2. Fail fast: panic assertions and explicit Result/Option return types.
  3. No hidden allocations: APIs surface ownership & lifetime.
  4. Cross-platform parity: identical semantic contracts on Win/macOS/Linux.
  5. Small & auditable: each module stays focused; headers avoid template bloat.
  6. “Borrow” before “own”: lightweight slice / Str views reduce copies.

🏁 Quick Start

Add SFC as a submodule or fetch + add_subdirectory:

git submodule add https://github.com/<yourfork>/sfc external/sfc

In your CMakeLists.txt:

add_subdirectory(external/sfc)
target_link_libraries(your_appPRIVATEsfc)

Minimal example:

#include"sfc/alloc.h"usingnamespacesfc;intmain() {
auto v = List<int>{};
for(auto i = 0; i < 10; ++i) {
v.push(i);
}
io::println("v[{}] = {}", v.len(), v);
return0;
}

🔬 Testing

Tests live next to sources (*.cxx) and are discovered via the single sfc_test runner.

cmake -B build -DCMAKE_BUILD_TYPE=Debug
cmake --build build -j
# Run all tests
./build/src/sfc_test[.exe]
# List all tests
./build/src/sfc_test --gtest_list_tests
# Build with AddressSanitizer
cmake -B build-asan -DSFC_ENABLE_ASAN=ON -DCMAKE_BUILD_TYPE=Debug
cmake --build build-asan -j
./build-asan/src/sfc_test

Test expectations use sfc::expect_* functions; a failure aborts fast with context.


🧩 Module Map (High Level)

alloc/ Box, Rc, String, List, allocation hooks
app/ CLI argument parsing (clap)
collections/ HashMap, HashSet, Queue
core/ Option, Result, Tuple, Variant, iterators, compile-time formatting, panics
env/ Environment variable access
ffi/ C strings, OS strings, platform string bridging
fs/ Path, file system wrappers
io/ File, stdio, buffered I/O, error model
log/ Core logging & pluggable backend structure
serde/ JSON, Base64
sync/ Mutex, Condvar, Atomics, MPMC queue
sys/ System-level abstractions
thread/ Thread creation & join primitives
time/ Clocks, durations

⚖️ Comparison Snapshot

Concernstd::SFC
Error handlingReturn codes / exceptionsResult<T,E> + panic expects
Optional valuesstd::optionalOption<T> (match-like ergonomics)
Stringsstd::string (allocator-heavy)Explicit owned vs view types
CollectionsBroad, legacy semanticsPurpose-built, STL-free, predictable
ABI / linkageVendor & version sensitiveSelf-contained static library
Formatting<format> heavy machineryLightweight compile-time checked fmt traits
Hidden allocationsPossible in algorithmsSurfaced / explicit

🗺️ Roadmap (Indicative)

  • Arena / bump allocator
  • Async executor + IO integration
  • More zero-copy serde backends
  • Tracing + structured logging sink
  • Additional lock-free data structures

Star or watch the repo to follow progress. PRs welcome (see below).


🤝 Contributing

We optimize for small, reviewable changes.

  1. Fork & branch (feat/xyz or fix/abc).
  2. Write tests next to the code (something.cxx).
  3. Keep STL out (no <vector>, etc.).
  4. Use existing patterns for memory & error handling.
  5. Run test runner; ensure no regressions.
  6. Open a PR with a concise rationale & benchmark notes if perf-related.

Please avoid large refactors without prior discussion (issue first).


❓ FAQ

Q: Why GPLv3? Alignment with strong copyleft for foundational correctness; future dual-licensing may be discussed.

Q: Can I use this in production today? Early stage; APIs may evolve. Lock a commit if shipping.

Q: Does it replace the entire standard library? No. It offers a curated core; you can mix parts, but goal is self-sufficiency.

Q: Exceptions? Design assumes exceptions are disabled or avoided; use Result + panics.

Q: Allocator strategy? Central hooks allow future pluggable arenas and tracking.


🔐 Safety Notes

Where raw pointers or unsafe casts are required, they’re isolated and documented. The public surface favors value semantics + explicit ownership.


🌐 Platform Support

PlatformStatusNotes
Windows (ClangCL)Unified APIs
Linux (Clang/GCC)Glibc & musl intended
macOS (Clang)Unified APIs

📦 Integration Tips

  • Build static: no global runtime surprises.
  • Disable exceptions / RTTI if you align project-wide.
  • LTO + dead stripping can further shrink binary (std not linked).

📜 License

Distributed under GPL v3 – see LICENSE. For commercial or alternative licensing discussions, open an issue.


⭐ Support & Momentum

If this vision resonates:

  • Star to signal interest
  • Watch for roadmap evolution
  • Open issues for pain points / gaps
  • Contribute focused PRs

Your feedback now directly shapes the direction before APIs harden.


� Acknowledgements

Inspired by ideas proven in the Rust standard library ecosystem and other modern systems frameworks, reinterpreted for idiomatic C++23 without legacy ballast.


Happy hacking — unleash modern patterns without dragging all of libstd along.

— The SFC Project

About

rust.std in c++

Topics

Resources

Stars

208 stars

Watchers

16 watching

Forks

Used by

Contributors

Languages