https://github.com/p-ranav/small_vector
"Small Vector" optimization for Modern C++: store up to a small number of items on the stack
https://github.com/p-ranav/small_vector
array buffer container cpp11 header-only heap memory-management modern-cpp optimization single-header single-header-lib small small-buffer-optimization stack vector
Last synced: 3 months ago
JSON representation
"Small Vector" optimization for Modern C++: store up to a small number of items on the stack
- Host: GitHub
- URL: https://github.com/p-ranav/small_vector
- Owner: p-ranav
- Created: 2020-08-08T19:08:01.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-05-06T14:01:53.000Z (over 4 years ago)
- Last Synced: 2025-05-05T11:44:51.944Z (5 months ago)
- Topics: array, buffer, container, cpp11, header-only, heap, memory-management, modern-cpp, optimization, single-header, single-header-lib, small, small-buffer-optimization, stack, vector
- Language: C++
- Homepage:
- Size: 69.3 KB
- Stars: 34
- Watchers: 2
- Forks: 2
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
small_vector
============"Small Vector" optimization for Modern C++: store up to a small number of items on the stack
## Example
```cpp
#include
#include#include
using namespace sv;int main() {
// This small vector can hold up to 4 items on the stack
small_vector vec{1, 2, 3, 4};
// It will move its contents to the heap if it
// contains more than four items:
vec.push_back(5);
// Access and modify contents
vec[0] = vec[1] + vec[2];// Iterate and print contents
std::copy(vec.begin(), vec.end(), std::ostream_iterator(std::cout, " "));}
```