From: David Sarrut Date: Thu, 27 Oct 2011 13:49:01 +0000 (+0200) Subject: Add MapToVec (first/second) functions. X-Git-Tag: v1.3.0~174^2~27 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=da7742b2188d694446ffedc1835b778fb71849b7;p=clitk.git Add MapToVec (first/second) functions. --- diff --git a/common/clitkCommon.h b/common/clitkCommon.h index 31f28dc..97808d8 100644 --- a/common/clitkCommon.h +++ b/common/clitkCommon.h @@ -209,6 +209,13 @@ namespace clitk { //-------------------------------------------------------------------- void PrintMemoryUsed(); + //-------------------------------------------------------------------- + // Convert a map to a vector + template + void MapToVecFirst(const M & m, V & v); + template + void MapToVecSecond(const M & m, V & v); + #include "clitkCommon.txx" } // end namespace diff --git a/common/clitkCommon.txx b/common/clitkCommon.txx index dc7f165..5ee83bd 100644 --- a/common/clitkCommon.txx +++ b/common/clitkCommon.txx @@ -195,6 +195,7 @@ std::string GetTypeAsString() } //-------------------------------------------------------------------- + //-------------------------------------------------------------------- template 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 +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 +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 */