Rheolef  7.1
an efficient C++ finite element environment
pair_util.h
Go to the documentation of this file.
1 #ifndef _RHEOLEF_PAIR_UTIL_H
2 #define _RHEOLEF_PAIR_UTIL_H
3 // useful class-functions for scanning containers of std::pair<T1,T2>
24 #include <utility> // for std::pair
25 #include <functional> // for std::unary_function
26 #include <iostream> // for debug
27 
28 namespace rheolef {
29 
30 template <class T1, class T2>
31 struct get_first : std::unary_function<std::pair<T1,T2>, T1> {
32  T1 operator() (const std::pair<T1,T2>& x) const { return x.first; }
33 };
34 template <class T1, class T2>
35 struct get_second : std::unary_function<std::pair<T1,T2>, T2> {
36  T2 operator() (const std::pair<T1,T2>& x) const { return x.second; }
37 };
38 
39 template<typename InputPairIterator, typename OutputPairIterator, typename UnaryOperation>
40 OutputPairIterator
42  InputPairIterator first,
43  InputPairIterator last,
44  OutputPairIterator result,
45  UnaryOperation unary_op)
46 {
47  for (; first != last; ++first, ++result)
48  (*result).second = unary_op ((*first).second);
49  return result;
50 }
51 #ifndef TO_CLEAN
52 template <class T1, class T2>
53 std::ostream&
54 operator<< (std::ostream& out, const std::pair<T1,T2>& x)
55 {
56  return out << "pair("<<x.first<<","<<x.second<<")";
57 }
58 #endif // TO_CLEAN
59 
60 } // namespace rheolef
61 #endif // _RHEOLEF_PAIR_UTIL_H
rheolef::io::out
Definition: rheostream.h:167
rheolef::get_second
Definition: pair_util.h:35
rheolef::get_first::operator()
T1 operator()(const std::pair< T1, T2 > &x) const
Definition: pair_util.h:32
rheolef::get_first
Definition: pair_util.h:31
rheolef
This file is part of Rheolef.
Definition: compiler_eigen.h:37
rheolef::get_second::operator()
T2 operator()(const std::pair< T1, T2 > &x) const
Definition: pair_util.h:36
rheolef::operator<<
std::ostream & operator<<(std::ostream &os, const catchmark &m)
Definition: catchmark.h:99
rheolef::pair_transform_second
OutputPairIterator pair_transform_second(InputPairIterator first, InputPairIterator last, OutputPairIterator result, UnaryOperation unary_op)
Definition: pair_util.h:41