An open API service indexing awesome lists of open source software.

https://github.com/bumbelbee777/cxxutil

A C++ library containing an implementation of the STL and other data structures and/or containers.
https://github.com/bumbelbee777/cxxutil

c-plus-plus cpp cpp20 header-only std stl stl-containers stl-files

Last synced: 7 months ago
JSON representation

A C++ library containing an implementation of the STL and other data structures and/or containers.

Awesome Lists containing this project

README

          

# Cxxutil.

A lightweight and freestanding C++20 library implementing various STL containers, allocators and other data structures such as:
- Vectors (`Vector`).
- Arrays (`Array`).
- Stacks (`Stack`).
- Linked lists (`LinkedList`).
- Binary search tree (`BinarySearchTree`).
- Functions (`Function`).
- Random access iterator (`Iterator`).
- Optional types (`Optional`).
- Mutable and non-mutable strings (`String` and `StringView` respectively).
- Queues (`Queue`).
- Heap allocator (`HeapAllocator`).
- Exceptions (`Exception`, `ExceptionPointer`).
- Smart pointers like boxes, unique and shared pointers (`Box`, `UniquePointer` and `SharedPointer` respectively).
- Maps and hashmaps (`Map` and `Hashmap` respectively).
- Regular expressions (`Regex`).
- Slices, both mutable and immutable (`Slice` and `ConstSlice` respectively).
- Graphs (`Graph`).
- Spinlocks and mutexes (`Spinlock` and `Mutex` respectively).
- FNV-1a algorithm and djb2 hashing algorithm for strings (`Hash` and `Hash` respectively).
- Pairs and tuples (`Pair` and `Tuple` respectively).
- C++20 string formatting and three-way comparison support.
- Complex numbers and quaternions (`Complex` and `Quaternion` respectively).

And more!

**Keep in mind it's still a work in progress and many features are incomplete and/or won't work as intended.**

# Example

```cxx
#include
#include

using namespace Cxxutil;

int main(int argv, char **argv) {
BinarySearchTree bst;
bst.Insert(5);
bst.Insert(2);
bst.Insert(8);
bst.Insert(1);
bst.Insert(4);
bst.Insert(7);
bst.Insert(9);

std::cout << "Binary Search Tree:\n";
bst.ForEach([](int& value, int index) {
std::cout << index << ": " << value << '\n';
});

std::cout << "Inorder traversal:\n";
bst.InOrderTraversal(std::cout);
std::cout << "\n";

std::cout << "Preorder traversal:\n";
bst.PreOrderTraversal(std::cout);
std::cout << "\n";

std::cout << "Postorder traversal:\n";
bst.PostOrderTraversal(std::cout);
std::cout << "\n";

std::cout << "Searching for value 7: " << std::boolalpha << bst.Search(7) << '\n';
std::cout << "Searching for value 3: " << std::boolalpha << bst.Search(3) << '\n';

bst.Remove(2);
std::cout << "After removing value 2:\n";
bst.ForEach([](int& Value, int Index) {
std::cout << index << ": " << value << '\n';
});

LinkedList ll;
ll.Append(1);
ll.Append(2);
ll.Append(3);
ll.Append(4);
ll.Append(5);

Queue queue;
queue.Enqueue(1);
queue.Enqueue(2);
queue.Enqueue(3);
queue.Enqueue(4);
queue.Enqueue(5);

std::cout << "Queue:\n";
while(!queue.IsEmpty()) {
std::cout << queue.Front() << '\n';
queue.Dequeue();
}

Stack MyStack;
Stack.Push(1);
Stack.Push(2);
Stack.Push(3);
Stack.Push(4);
Stack.Push(5);
MyStack.ForEach([&](int &Item, int Index) {
std::cout << Item << '\n';
});
return 0;
}
```