Skip to content

Instantly share code, notes, and snippets.

@rchatsiri
Created October 13, 2010 16:56
Show Gist options
  • Save rchatsiri/624441 to your computer and use it in GitHub Desktop.
Save rchatsiri/624441 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <boost/utility.hpp>
template<typename T>
void deleter(T *ptr){
delete ptr;
}
template<typename T>
class InsertValue : private boost::noncopyable{
private:
std::vector<T> elements;
public:
// old senario
void deleteValue(){
for(size_t n = 0; n < elements.size(); ++n){
if((*elements)[n] != 0){
delete(*elements)[n];
}
}
}
//new senario
~InsertValue(){
std::for_each(elements.begin(),elements.end(),deleter);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment