Skip to content

Instantly share code, notes, and snippets.

@shawnchin
Created May 9, 2012 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shawnchin/2644367 to your computer and use it in GitHub Desktop.
Save shawnchin/2644367 to your computer and use it in GitHub Desktop.
class VectorWrapperBase {
public:
virtual ~VectorWrapperBase() {}
virtual void reserve(unsigned int n) = 0;
virtual VectorWrapperBase* clone() const = 0;
};
inline VectorWrapperBase* new_clone(const VectorWrapperBase& a) {
return a.clone();
}
template <typename T>
class VectorWrapper: public VectorWrapperBase {
public:
typedef T data_type;
typedef std::vector<T> vector_type;
void reserve(unsigned int n) { v_.reserve(n); }
VectorWrapper<T>* clone() const { return new VectorWrapper<T>(*this); }
private:
std::vector<T> v_;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment