Gobelijn API documentation  - generated for commit a0cbea7
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros Pages
trans.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 <list>
25 
26 namespace {
27 
31 class Incrementor
32 {
33 public:
34  explicit Incrementor(unsigned int n) : fNum(n) {}
35 
36  template <typename T>
37  T operator()(T t)
38  {
39  for (unsigned int i = 1; i <= fNum; i++) {
40  t++;
41  }
42  return t;
43  }
44 
45 private:
46  unsigned int fNum;
47 };
48 
49 } // namespace
50 
51 int main()
52 {
53  std::vector<int> v(8);
54  std::list<int> l(8);
55  generate(v.begin(), v.end(), RandInt(3, static_cast<int>(v.size())));
56 
57  // Out of place transform
58  Incrementor incr(2);
59  transform(v.begin(), v.end(), l.begin(), incr);
60  std::cout << make_range(v) << std::endl << make_range(l) << std::endl;
61 
62  // In place transform
63  transform(v.begin(), v.end(), v.begin(), incr);
64  std::cout << make_range(v) << std::endl;
65 
66  return 0;
67 }
68 // END_SNIPPET{FullSource}
int main()
Definition: trans.cpp:51
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