Rheolef  7.2
an efficient C++ finite element environment
 
Loading...
Searching...
No Matches
pair_util.h
Go to the documentation of this file.
1#ifndef _RHEOLEF_PAIR_UTIL_H
2#define _RHEOLEF_PAIR_UTIL_H
23// 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
28namespace rheolef {
29
30template <class T1, class T2>
31struct get_first : std::unary_function<std::pair<T1,T2>, T1> {
32 T1 operator() (const std::pair<T1,T2>& x) const { return x.first; }
33};
34template <class T1, class T2>
35struct 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
39template<typename InputPairIterator, typename OutputPairIterator, typename UnaryOperation>
40OutputPairIterator
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
52template <class T1, class T2>
53std::ostream&
54operator<< (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
This file is part of Rheolef.
std::ostream & operator<<(std::ostream &os, const catchmark &m)
Definition catchmark.h:99
OutputPairIterator pair_transform_second(InputPairIterator first, InputPairIterator last, OutputPairIterator result, UnaryOperation unary_op)
Definition pair_util.h:41
T1 operator()(const std::pair< T1, T2 > &x) const
Definition pair_util.h:32
T2 operator()(const std::pair< T1, T2 > &x) const
Definition pair_util.h:36