This project is a custom implementation of the C++ Standard Template Library (STL) forward_list.
The goal is to understand how the STL container works internally by building it from scratch,
including various member functions, iterators, and algorithms such as sort, merge, and reverse.
.
├── build_failed.sh // Script for simulating failed build
├── build_testing.sh // Script for running unit tests
├── CMakeLists.txt // CMake configuration
├── compile.sh // Compile main implementation
├── compile_sort.sh // Compile sorting-related code
├── CONTRIBUTING.md // Contribution guidelines
├── header/ // Header files
│ └── forward_list.hpp // Forward list template implementation
├── implementation/ // Implementation details
│ ├── implementation.cpp
│ └── implementation_sort.cpp
├── LICENSE // License file (MIT)
├── src/ // Source code prototypes
│ ├── forward_list.cpp
│ ├── merge_list.cpp
│ └── merge_sort.cpp
├── test/ // Unit tests
│ └── testing.cpp
└── README.md // Project documentation- Compiler: g++ 10+/clang++ 12+
- OS: Linux(recomended),MacOS,Mikocok
Clone this repo
git clone https://github.com/Build-X-From-Scratch/forward_list_sratch.gitcp -r forward_list_sratch/header/forward_list.hpp .If your project uses CMake, you can integrate this library using FetchContent. Add the following code to your CMakeLists.txt:
include(FetchContent)
FetchContent_Declare(
forward_lists
GIT_REPOSITORY https://github.com/Build-X-From-Scratch/forward_list_sratch.git
GIT_TAG v1.0.0
)
FetchContent_MakeAvailable(forward_lists)Then link the library to your executable:
add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE forward_list)cmake_minimum_required(VERSION 3.14)
project(MyProject)
set(CMAKE_CXX_STANDARD 17)
include(FetchContent)
FetchContent_Declare(
forward_lists
GIT_REPOSITORY https://github.com/namamu/mystl.git
GIT_TAG v1.0.0
)
FetchContent_MakeAvailable(forward_lists)
add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE forward_list)#include <iostream>
#include <vector>
#include "../header/forward_list.hpp" //->this header
int main(){
std::cout << "Testing" << std::endl;
forward_lists<int>flst = {1,2,3};
flst.pop_front();
flst.pop_front();
flst.print_all(flst.begin(),flst.end()); //3
return 0;
} if you use g++ then:
g++ -stdc=c++20 example.cpp -o example
./exampleif you use clang then:
clang++ -stdc=c++20 example -o example
./example| Feature | Status |
|---|---|
| insert_after | ✅ Done |
| erase_after | ✅ Done |
| push_front | ✅ Todo |
| pop_front | ✅ Todo |
| reverse | ✅ Todo |
| unique | ✅ Todo |
| Unit Testing | ✅ Todo |
| Sort | ✅ Todo |
| Swap | ✅ Todo |
| emplace_back | ✅ Todo |
| emplace_front | ✅ Todo |
| Assign | ✅ Todo |
| Merge | ✅ Todo |
if you want read details benchmark,you can read in this benchmark result
This project is licensed under the MIT License.
You are free to use, modify, and distribute it with proper attribution.
