Adaptagrams
util.h
1 /*
2  * vim: ts=4 sw=4 et tw=0 wm=0
3  *
4  * libtopology - Classes used in generating and managing topology constraints.
5  *
6  * Copyright (C) 2007-2008 Monash University
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  * See the file LICENSE.LGPL distributed with the library.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17  *
18 */
19 
20 #ifndef TOPOLOGY_UTIL_H
21 #define TOPOLOGY_UTIL_H
22 namespace topology {
23 /*
24  * templated delete functor for use in for_each loop over vector
25  */
26 struct delete_object
27 {
28  template <typename T>
29  void operator()(T *ptr){ delete ptr;}
30 };
31 /*
32  * Sum over the results of calling operation for each member in the
33  * iterator. Handier than std::accumulate because we can use with
34  * mem_fun to pass in a getter method.
35  */
36 template <class InputIterator, class T, class Operation >
37 T sum_over(InputIterator beg, InputIterator end, T init, Operation op)
38 {
39  for ( ; beg != end; ++beg)
40  init = init + op(*beg);
41  return init;
42 }
43 } // namespace topology
44 #endif // TOPOLOGY_UTIL_H
libtopology: Extensions for topology preservation for libcola and libavoid libraries.
Definition: shape.h:41