]> Creatis software - clitk.git/blobdiff - common/clitkCommon.txx
Add MapToVec (first/second) functions.
[clitk.git] / common / clitkCommon.txx
index dc7f1653c45d5d9e3538043297ca89408c64b80e..5ee83bdca8f4f3efc23ae2aa8dc12ad28a2fe36e 100644 (file)
@@ -195,6 +195,7 @@ std::string GetTypeAsString()
 }
 //--------------------------------------------------------------------
 
+
 //--------------------------------------------------------------------
 template<class ImageType>
 void CloneImage(const typename ImageType::Pointer & input, typename ImageType::Pointer & output)
@@ -217,5 +218,22 @@ void CloneImage(const typename ImageType::Pointer & input, typename ImageType::P
 }
 //--------------------------------------------------------------------
 
+
+//--------------------------------------------------------------------
+// http://stackoverflow.com/questions/771453/copy-map-values-to-vector-in-stl
+template <typename M, typename V> 
+void MapToVecFirst(const  M & m, V & v) {
+  for( typename M::const_iterator it = m.begin(); it != m.end(); ++it ) {
+    v.push_back( it->first );
+  }
+}
+template <typename M, typename V> 
+void MapToVecSecond(const  M & m, V & v) {
+  for( typename M::const_iterator it = m.begin(); it != m.end(); ++it ) {
+    v.push_back( it->second );
+  }
+}
+//--------------------------------------------------------------------
+
 #endif /* end #define CLITKCOMMON_TXX */