mystl is a header-only C++17 project that reimplements a subset of the C++ Standard Template Library as a learning exercise. It provides container, algorithm, and utility components that mirror familiar STL interfaces while staying small and easy to read.
- Containers:
MyVector,MyList,MyDeque,MyQueue,MyStack,MySet,MyMap,MyUnorderedSet,MyUnorderedMap,MyBinaryHeap,MyPriorityQueue,MyMultiMap,MyMultiSet... - Smart pointers:
MyUniquePtr,MySharedPtr,MyWeakPtr, plusMyMakeSharedwith custom deleter support and safenullptrresets - Infrastructure pieces such as
MyAllocator, iterator adapters (e.g.vector_iterator,reverse_iterator), and a red-black tree backbone for ordered containers. - Algorithm utilities (
sort,find,reverse,copy,fill, ...) implemented ininclude/my_algorithm.h. - Header-only usage: include what you need and link against the
mystlinterface target. - Example program (
main.cpp) that exercises the major containers and algorithms.
- C++17 compatible compiler (tested with GCC)
- CMake 3.16 or newer
cmake -S . -B build
cmake --build buildThis builds the optional mystl_demo example executable. Disable it with -DMYSTL_BUILD_EXAMPLES=OFF.
./build/mystl_demoinclude/– header implementations for containers, algorithms, utilities, allocator, iterators.main.cpp– demonstration program.CMakeLists.txt– CMake project definition; installs headers when you callcmake --install.build/– default out-of-source build directory (created by the commands above).src/– reserved for future source-based extensions.
#include "my_vector.h"
#include "my_algorithm.h"
int main() {
mystl::MyVector<int> values = {5, 2, 4, 1, 3};
mystl::sort(values.begin(), values.end());
for (int v : values) {
std::cout << v << ' ';
}
}