A C++ std::vector utility library that is simple, powerful, and efficient
A header-only library providing enhanced utilities for working with std::vector, featuring comprehensive tests and benchmarks.
- Header-only: Simply include
stevensVectorLib.hppin your project - Fully tested: 88 comprehensive unit tests with Google Test
- Benchmarked: Performance benchmarks with Google Benchmark
- Modern C++17: Clean, efficient, and well-documented code
- Zero dependencies: Only requires C++ standard library
contains()- Check if vector contains an elementeraseAllOf()- Remove all instances of an elementsumAll()/multiplyAll()- Aggregate operationsfindElementIndex()- Find index of elementfindMin()- Find minimum elementgetRandomElement()- Get random element from vectorconcat()- Concatenate two vectorsgetUncommonElements()- Get symmetric difference of vectorsgetLargestVectorElement()- Find largest vector in 2D vectorgetLongestStringElement()- Find longest string in vectorreorient2DVector()- Transpose a 2D vectoreraseDuplicateElements()- Remove duplicates while preserving orderdifference()- Remove elements from first vector that appear in secondpopFront()- Remove and return first elementvecOfStrings_to_vecOfInts()/vecOfStrings_to_vecOfLongLongInts()- String to numeric conversions
Simply copy stevensVectorLib.hpp into your project and include it:
#include "stevensVectorLib.hpp"Clone the repository and use CMake:
git clone https://github.com/Bucephalus-Studios/stevensVectorLib.git
cd stevensVectorLib
mkdir build && cd build
cmake ..
make
ctest # Run testshttps://github.com/Nord-Tech-Systems-LLC/beldum_package_manager
mkdir new_project
cd new_project
beldum init
beldum install stevensVectorLib#include <vector>
#include <string>
#include "stevensVectorLib.hpp"
int main()
{
// Check if vector contains an element
std::vector<int> numbers = {1, 2, 3, 4, 5};
bool has_three = stevensVectorLib::contains(numbers, 3); // true
// Remove duplicates
std::vector<int> with_dupes = {1, 2, 2, 3, 3, 3};
auto unique = stevensVectorLib::eraseDuplicateElements(with_dupes); // {1, 2, 3}
// Sum all elements
int sum = stevensVectorLib::sumAll(numbers, 0); // 15
// Concatenate vectors
std::vector<int> more_numbers = {6, 7, 8};
auto combined = stevensVectorLib::concat(numbers, more_numbers); // {1, 2, 3, 4, 5, 6, 7, 8}
return 0;
}mkdir build && cd build
cmake ..
make -j$(nproc)ctest --output-on-failure./benchmarks/vector_lib_benchmarksBUILD_TESTS(default: ON) - Build unit testsBUILD_BENCHMARKS(default: ON) - Build performance benchmarks
To disable tests or benchmarks:
cmake -DBUILD_TESTS=OFF -DBUILD_BENCHMARKS=OFF ..- C++17 compatible compiler
- CMake 3.14 or higher (for building tests/benchmarks)
This library has been optimized for:
- Simplicity - Clear, straightforward implementations
- Readability - Well-documented with descriptive names
- Functional abstraction - Reusable, composable functions
- Encapsulation - All functions in
stevensVectorLibnamespace - DRY principle - No code duplication
- Efficiency - Pass by reference, reserve space, O(n) or better complexity
- Speed - Optimized algorithms and minimal allocations
- Good variable names - Self-documenting code
- Low nesting - Maximum 2 levels of nesting per function
See LICENSE file for details.
Contributions are welcome! Please feel free to submit pull requests.