p-ranav / small_vector

"Small Vector" optimization for Modern C++: store up to a small number of items on the stack

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

small_vector

"Small Vector" optimization for Modern C++: store up to a small number of items on the stack

Example

#include <iostream>
#include <iterator>

#include <small_vector/small_vector.h>
using namespace sv;

int main() {
 
  // This small vector can hold up to 4 items on the stack
  small_vector<int, 4> 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<int>(std::cout, " "));

}

About

"Small Vector" optimization for Modern C++: store up to a small number of items on the stack


Languages

Language:C++ 99.5%Language:CMake 0.5%Language:Shell 0.0%