Libbarrett  1.2.4
include/barrett/detail/stl_utils.h
Go to the documentation of this file.
00001 
00034 #ifndef BARRETT_DETAIL_STL_UTILS_H_
00035 #define BARRETT_DETAIL_STL_UTILS_H_
00036 
00037 
00038 #include <algorithm>
00039 
00040 
00041 namespace barrett {
00042 namespace detail {
00043 
00044 
00045 void waitForEnter();
00046 
00047 template<typename Container>
00048 inline void replaceWithNull(Container& container, typename Container::const_reference value)
00049 {
00050         std::replace(container.begin(), container.end(),
00051                         const_cast<typename Container::value_type&>(value),
00052                         static_cast<typename Container::value_type>(NULL));
00053 }
00054 
00055 
00056 // Delete pointers in an STL sequence container.
00057 //
00058 // Code stolen from Thinking in C++, 2nd Ed., Vol. 2, p.534
00059 
00060 template<class Seq> void purge(Seq& c) {  //NOLINT
00061         typename Seq::iterator i;
00062         for (i = c.begin(); i != c.end(); ++i) {
00063                 delete *i;
00064                 *i = 0;
00065         }
00066 }
00067 
00068 // Iterator version:
00069 template<class InpIt> void purge(InpIt begin, InpIt end) {
00070         while (begin != end) {
00071                 delete *begin;
00072                 *begin = 0;
00073                 ++begin;
00074         }
00075 }
00076 
00077 
00078 }
00079 }
00080 
00081 
00082 #endif /* BARRETT_DETAIL_STL_UTILS_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Defines