rheolef  6.3
pair_util.h
Go to the documentation of this file.
1 #ifndef _RHEOLEF_PAIR_UTIL_H
2 #define _RHEOLEF_PAIR_UTIL_H
3 // usefull class-functions for scanning containers of std::pair<T1,T2>
4 #include <utility> // for std::pair
5 #include <functional> // for std::unary_function
6 #include <iostream> // for debug
7 
8 namespace rheolef {
9 
10 template <class T1, class T2>
11 struct get_first : std::unary_function<std::pair<T1,T2>, T1> {
12  T1 operator() (const std::pair<T1,T2>& x) const { return x.first; }
13 };
14 template <class T1, class T2>
15 struct get_second : std::unary_function<std::pair<T1,T2>, T2> {
16  T2 operator() (const std::pair<T1,T2>& x) const { return x.second; }
17 };
18 
19 template<typename InputPairIterator, typename OutputPairIterator, typename UnaryOperation>
20 OutputPairIterator
22  InputPairIterator first,
23  InputPairIterator last,
24  OutputPairIterator result,
25  UnaryOperation unary_op)
26 {
27  for (; first != last; ++first, ++result)
28  (*result).second = unary_op ((*first).second);
29  return result;
30 }
31 #ifndef TO_CLEAN
32 template <class T1, class T2>
33 std::ostream&
34 operator<< (std::ostream& out, const std::pair<T1,T2>& x)
35 {
36  return out << "pair("<<x.first<<","<<x.second<<")";
37 }
38 #endif // TO_CLEAN
39 
40 } // namespace rheolef
41 #endif // _RHEOLEF_PAIR_UTIL_H
42