[ObjectHandler-cvs] ObjectHandler/oh utilities.hpp,1.15,1.16
Brought to you by:
ericehlers,
nando
From: Ferdinando A. <na...@us...> - 2007-01-04 17:11:32
|
Update of /cvsroot/objecthandler/ObjectHandler/oh In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv17773/oh Modified Files: utilities.hpp Log Message: new ohFilter function Index: utilities.hpp =================================================================== RCS file: /cvsroot/objecthandler/ObjectHandler/oh/utilities.hpp,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** utilities.hpp 2 Jan 2007 11:07:43 -0000 1.15 --- utilities.hpp 4 Jan 2007 17:11:27 -0000 1.16 *************** *** 25,28 **** --- 25,30 ---- #include <oh/objhandlerdefines.hpp> + #include <oh/exception.hpp> + #include <boost/any.hpp> #include <string> #include <vector> *************** *** 84,87 **** --- 86,106 ---- bool token_compress); + template< typename T> + std::vector<T> filter(const std::vector<T> &in, + const std::vector<bool> &flags) { + std::size_t size = in.size(); + OH_REQUIRE(size==flags.size(), + "size mismatch between value vector (" << size << + ") and flag vector (" << flags.size() << ")"); + + std::vector<T> out; + out.reserve(size); //excess capacity + + for (std::size_t i=0; i<size; ++i) + if (flags[i]) out.push_back(in[i]); + + return out; + } + //@} } |