Created
October 13, 2010 16:56
-
-
Save rchatsiri/624441 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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