Branch libreoffice-5-0-4
[LibreOffice.git] / include / o3tl / compat_functional.hxx
blob6d04e6744ca37d4186cb5d127f2272bcca966dc7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
4 * Copyright (c) 1994
5 * Hewlett-Packard Company
7 * Copyright (c) 1996-1998
8 * Silicon Graphics Computer Systems, Inc.
10 * Copyright (c) 1997
11 * Moscow Center for SPARC Technology
13 * Copyright (c) 1999
14 * Boris Fomitchev
16 * This material is provided "as is", with absolutely no warranty expressed
17 * or implied. Any use is at your own risk.
19 * Permission to use or copy this software for any purpose is hereby granted
20 * without fee, provided the above notices are retained on all copies.
21 * Permission to modify the code and to distribute modified code is granted,
22 * provided the above notices are retained, and a notice that the code was
23 * modified is included with the above copyright notice.
28 * Lifted and paraphrased from STLport - with additions from Fridrich
29 * Strba and Thorsten Behrens
32 #ifndef INCLUDED_O3TL_COMPAT_FUNCTIONAL_HXX
33 #define INCLUDED_O3TL_COMPAT_FUNCTIONAL_HXX
35 #include <functional>
37 namespace o3tl
40 /// Functor, given two parameters, return the first
41 template<class T1,class T2>
42 struct project1st : public std::binary_function<T1, T2, T1>
44 T1 operator()(const T1& y, const T2&) const
46 return y;
50 /// Functor, given two parameters, return the second
51 template<class T1,class T2>
52 struct project2nd : public std::binary_function<T1, T2, T2>
54 T2 operator()(const T1&, const T2& x) const
56 return x;
60 /// Select first value of a pair
61 template<class P>
62 struct select1st : public std::unary_function<P, typename P::first_type>
64 const typename P::first_type& operator()(const P& y) const
66 return y.first;
70 /// Select second value of a pair
71 template<class P>
72 struct select2nd : public std::unary_function<P, typename P::second_type>
74 const typename P::second_type& operator()(const P& y) const
76 return y.second;
80 /// Call F1 with the result of F2 applied to the one input parameter
81 template<class F1, class F2>
82 class unary_compose : public std::unary_function<typename F2::argument_type, typename F1::result_type>
84 public:
85 unary_compose(const F1& fnction1, const F2& fnction2) : ftor1(fnction1), ftor2(fnction2) {}
87 typename F1::result_type operator()(const typename F2::argument_type& y) const
89 return ftor1(ftor2(y));
92 protected:
93 F1 ftor1;
94 F2 ftor2;
97 /// Create functor that calls F1 with the result of F2 applied to the one input parameter
98 template<class F1, class F2>
99 inline unary_compose<F1, F2> compose1(const F1& fnction1, const F2& fnction2)
101 return unary_compose<F1, F2>(fnction1, fnction2);
104 } // namespace o3tl
106 #endif
108 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */