SHORE API
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
helpers.hpp
Go to the documentation of this file.
1 
2 /*
3  * Copyright 2008,2009,2010,2011,2012 Stephan Ossowski, Korbinian Schneeberger,
4  * Felix Ott, Joerg Hagmann, Alf Scotland, Sebastian Bender
5  *
6  * This file is part of SHORE.
7  *
8  * SHORE is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * SHORE is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with SHORE. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
25 
26 #ifndef SHORE_CONTAINER_HELPERS_HPP__
27 #define SHORE_CONTAINER_HELPERS_HPP__
28 
29 #ifdef HAVE_CONFIG_H
30  #include "config.h"
31 #endif
32 
33 #include <vector>
34 
35 namespace shore {
36 
38 template<class T>
39 std::vector<typename T::key_type> map_keys(const T& m)
40 {
41  typedef typename T::const_iterator i_t;
42  typedef typename T::key_type key_t;
43 
44  std::vector<key_t> ret;
45 
46  for(i_t i=m.begin();i!=m.end();++i)
47  {
48  ret.push_back(i->first);
49  }
50 
51  return ret;
52 }
53 
55 template<class T>
56 std::vector<typename T::mapped_type> map_values(const T& m)
57 {
58  typedef typename T::const_iterator i_t;
59  typedef typename T::mapped_type value_t;
60 
61  std::vector<value_t> ret;
62 
63  for(i_t i=m.begin();i!=m.end();++i)
64  {
65  ret.push_back(i->second);
66  }
67 
68  return ret;
69 }
70 
71 } // namespace
72 
73 #endif // SHORE_CONTAINER_HELPERS_HPP__
74