#ifndef __RAT_Delete__ #define __RAT_Delete__ #include #include #include namespace RAT { template void deepdelete_vector(std::vector &vect) { typename std::vector::iterator i; for (i=vect.begin(); i != vect.end(); i++) delete (*i); vect.clear(); } template void deepcopy_vector(std::vector &dest, const std::vector &src) { deepdelete_vector(dest); dest.resize(src.size()); for (unsigned i=0; i < src.size(); i++) dest[i] = dynamic_cast(src[i]->Clone()); // Use Clone() for proper polymorphism } template class CompareFunc: public std::binary_function { public: virtual bool operator() (T*, T*) = 0; }; // Clear a vector, forcing capacity to zero. // In C++98, std::vector::clear does not change capacity. template void clear_vector(std::vector& vect) { std::vector().swap(vect); } // Get the keys in a map // // target: map to get keys from // Returns vector of keys template std::vector keys_in_map( const std::map& target ) { std::vector keys; for( typename std::map::const_iterator iTer = target.begin(); iTer != target.end(); iTer++ ) keys.push_back( iTer->first ); return keys; } // Get the largest key in a map // // target: map to get keys from // Returns largest key template T largest_key( const std::map& target ) { return target.rbegin()->first; } } // namespace RAT #endif