1
0
Fork
You've already forked cplus
0
Alternative standard library for C++.
  • C++ 100%
2025年08月21日 19:37:33 +08:00
cplus BitTrie: for_string() iterator, tweaks; add examples/trie.cpp; BitBuilder: add get_string() 2025年08月21日 19:37:33 +08:00
examples BitTrie: for_string() iterator, tweaks; add examples/trie.cpp; BitBuilder: add get_string() 2025年08月21日 19:37:33 +08:00
tests BitTrie: for_string() iterator, tweaks; add examples/trie.cpp; BitBuilder: add get_string() 2025年08月21日 19:37:33 +08:00
.gitignore add folder "tests", move and rename files, tweaks 2024年01月20日 13:17:19 +08:00
README.md BitTrie: for_string() iterator, tweaks; add examples/trie.cpp; BitBuilder: add get_string() 2025年08月21日 19:37:33 +08:00

C+

C+ is an alternative standard library for C++.

Compare to STL, it's drastically smaller and simpler, compiles much faster, and has better error messages. Its interfaces are completely different from STL.

C+ is designed with allocators in mind. You can easily use custom allocators on everything that uses dynamic memory, for performance or debugging purposes.

Overview

An overview of files:

module.cpp main "module" file of C+
code_generator.cpp code generation utils, not included by default
core.cpp value type definitions
utils.cpp misc utils (defer, tuple, swap, operator wrappers, etc.)
math.cpp math utils
random.cpp random number generator interface and some basic PRNGs
allocator.cpp memory, allocator interface, and a linear arena allocator
array.cpp array view and dynamic array
queue.cpp fixed size queue, dynamic priority queue
list.cpp doubly linked list
algorithms.cpp useful algorithms (sorting, binary search, array filter/removal)
string.cpp string view, string builder, inplace string
parse.cpp string parsing utils
unicode.cpp unicode decode/encode/convert
io.cpp console IO and load/save file
bit.cpp bit utils, bit table, bit builder
hash.cpp basic hash functions
hash_table.cpp simple hash table
trie.cpp simple bit trie

Simple Example

Create a hello.cpp file in an empty folder, and put the subfolder cplus in there:

  • hello.cpp
#include "cplus/module.cpp"
int main() {
 auto message = string("Hello! This is a message!");
 while (message.count) {
 print(string("[@]\n"), message.eat_by_spaces());
 }
}

Compile and run it:

g++ hello.cpp -o hello && ./hello

It should output something like this:

[Hello!]
[This]
[is]
[a]
[message!]

Notes

  • The primary goals of C+ are simplicity and clarity. It's not optimized, therefore can be slower than STL, but sometimes it's faster. See tests/performance.cpp for comparisons.

  • C+'s data structures do not care about constructors and destructors. If you want to use them for types that have constructors and destructors, you need to do the these parts manually.

  • C+ doesn't use exceptions or virtual at all. If you also don't, you can safely use compiler flags like -fno-exceptions and -fno-rtti.

  • Your compiler may link to STL despite that C+ doesn't use it. Since you probably don't want to use STL, you can disable linking to STL, to get rid of that unnecessary dependency, and make compilation faster.

  • Currently, if you want to use C+, you must use Unity Build for your project.

  • It's recommended to copy the whole C+ codebase to your project, and you can change it or add features if needed. C+'s API may change anytime.

  • Although much better than STL, error messages of C+ are still not good. This is maybe not something that can be fixed at library level, but I want to improve it if I can.

Dependencies

  • A C++17 compiler: C+ is written in C++17.
  • C standard library: C+ uses some C standard library functions.

License

This repository is dedicated to public domain.