Skip to content

Instantly share code, notes, and snippets.

@piti118
Created December 23, 2011 11:00
Show Gist options
  • Save piti118/1513875 to your computer and use it in GitHub Desktop.
Save piti118/1513875 to your computer and use it in GitHub Desktop.
Vector Inserter
#include <vector>
//vector_inserter(idea taken from boost for those who don't wanna install boost)
//try vector<int> v; v+=1,2,3,4,5,6;
template <class T> class vector_inserter{
public:
std::vector<T>& v;
vector_inserter(std::vector<T>& v):v(v){}
vector_inserter& operator,(const T& val){v.push_back(val);return *this;}
};
template <class T> vector_inserter<T>& operator+=(std::vector<T>& v,const T& x){
return vector_inserter<T>(v),x;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment