ML Reference
|
00001 // **InsertLicense** code 00002 //---------------------------------------------------------------------------------- 00008 //---------------------------------------------------------------------------------- 00009 #ifndef __mlStdAlgorithms_H 00010 #define __mlStdAlgorithms_H 00011 00012 #ifndef __mlUtilsSystem_H 00013 #include "mlUtilsSystem.h" 00014 #endif 00015 00016 #include "mlSystemWarningsDisable.h" 00017 #include <algorithm> 00018 #include "mlSystemWarningsRestore.h" 00019 00020 ML_UTILS_START_NAMESPACE 00021 00023 template <typename T> 00024 inline bool vector_contains(const std::vector<T> &vec, const T& value) { 00025 return std::find(vec.begin(), vec.end(), value) != vec.end(); 00026 } 00027 00029 template <typename T> 00030 inline bool vector_remove(std::vector<T> &vec, const T& value) { 00031 typename std::vector<T>::iterator it = std::find(vec.begin(), vec.end(), value); 00032 if (it != vec.end()) { 00033 vec.erase(it); 00034 return true; 00035 } else { 00036 return false; 00037 } 00038 } 00039 00041 template <typename T> 00042 inline void vector_remove_all(std::vector<T> &vec, const T& value) { 00043 typename std::vector<T>::iterator it = vec.begin(); 00044 while (it != vec.end()) { 00045 if (*it == value) { 00046 it = vec.erase(it); 00047 } else { 00048 ++it; 00049 } 00050 } 00051 } 00052 00054 template <typename T> 00055 inline bool vector_replace_by_NULL(std::vector<T> &vec, const T& value) { 00056 typename std::vector<T>::iterator it = std::find(vec.begin(), vec.end(), value); 00057 if (it != vec.end()) { 00058 *it = NULL; 00059 return true; 00060 } else { 00061 return false; 00062 } 00063 } 00064 00065 ML_UTILS_END_NAMESPACE 00066 00067 #endif // __mlStdAlgorithms_H