Gobelijn API documentation  - generated for commit a0cbea7
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros Pages
freq.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the gobelijn software.
3  * Gobelijn is free software: you can redistribute it and/or modify it
4  * under the terms of the GNU General Public License as published by the
5  * Free Software Foundation, either version 3 of the License, or any later
6  * version. Gobelijn is distributed in the hope that it will be useful, but
7  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
8  * or FITNESS FOR A PARTICULAR PURPOSE.
9  * See the GNU General Public License for details. You should have received
10  * a copy of the GNU General Public License along with the software. If not,
11  * see <http://www.gnu.org/licenses/>.
12  *
13  * Copyright 2012, Jan Broeckhove, CoMP/UA.
14  */
20 // BEGIN_SNIPPET{FullSource}
21 #include "RandInt.h"
22 #include "Range.h"
23 #include <algorithm>
24 #include <map>
25 
26 template <typename It>
27 std::map<typename It::value_type, unsigned int> freq(It first, It last)
28 {
29  std::map<typename It::value_type, unsigned int> m;
30  for (It it = first; it != last; ++it) {
31  m[*it]++;
32  }
33  return m;
34 }
35 
36 int main()
37 {
38  std::vector<int> v(20);
39  std::generate(v.begin(), v.end(), RandInt(2, 10));
40  std::cout << make_range(v) << std::endl << make_range(freq(v.begin(), v.end())) << std::endl;
41  return 0;
42 }
43 // END_SNIPPET{FullSource}
int main()
Definition: freq.cpp:36
std::map< typename It::value_type, unsigned int > freq(It first, It last)
Definition: freq.cpp:27
Produce random integer (int) values.
Definition: RandInt.h:27
Range (see also boost Range library)
Functor produces random values.
Range< Iter > make_range(Iter it1, Iter it2)
Definition: Range.h:34