680 |
11 Oct 06 |
jari |
1 |
#ifndef _theplu_yat_utility_stl_utility_ |
2730 |
24 Apr 12 |
peter |
2 |
#define _theplu_yat_utility_stl_utility_ |
675 |
10 Oct 06 |
jari |
3 |
|
58 |
14 Apr 04 |
jari |
// $Id$ |
58 |
14 Apr 04 |
jari |
5 |
|
570 |
05 Apr 06 |
jari |
6 |
/* |
2119 |
12 Dec 09 |
peter |
Copyright (C) 2004 Jari Häkkinen |
2119 |
12 Dec 09 |
peter |
Copyright (C) 2005 Jari Häkkinen, Peter Johansson, Markus Ringnér |
2119 |
12 Dec 09 |
peter |
Copyright (C) 2006 Jari Häkkinen |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2007 Peter Johansson |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2008 Jari Häkkinen, Peter Johansson |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2018, 2023 Peter Johansson |
570 |
05 Apr 06 |
jari |
13 |
|
1437 |
25 Aug 08 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
570 |
05 Apr 06 |
jari |
15 |
|
675 |
10 Oct 06 |
jari |
The yat library is free software; you can redistribute it and/or |
675 |
10 Oct 06 |
jari |
modify it under the terms of the GNU General Public License as |
1486 |
09 Sep 08 |
jari |
published by the Free Software Foundation; either version 3 of the |
675 |
10 Oct 06 |
jari |
License, or (at your option) any later version. |
570 |
05 Apr 06 |
jari |
20 |
|
675 |
10 Oct 06 |
jari |
The yat library is distributed in the hope that it will be useful, |
675 |
10 Oct 06 |
jari |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
675 |
10 Oct 06 |
jari |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
570 |
05 Apr 06 |
jari |
General Public License for more details. |
570 |
05 Apr 06 |
jari |
25 |
|
570 |
05 Apr 06 |
jari |
You should have received a copy of the GNU General Public License |
1487 |
10 Sep 08 |
jari |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
570 |
05 Apr 06 |
jari |
28 |
*/ |
570 |
05 Apr 06 |
jari |
29 |
|
58 |
14 Apr 04 |
jari |
30 |
/// |
58 |
14 Apr 04 |
jari |
/// \file stl_utility.h |
58 |
14 Apr 04 |
jari |
32 |
/// |
58 |
14 Apr 04 |
jari |
/// There are a number of useful functionality missing in the Standard |
58 |
14 Apr 04 |
jari |
/// Template Library, STL. This file is an effort to provide |
58 |
14 Apr 04 |
jari |
/// extensions to STL functionality. |
58 |
14 Apr 04 |
jari |
36 |
/// |
58 |
14 Apr 04 |
jari |
37 |
|
2286 |
27 Jun 10 |
peter |
38 |
#include "concept_check.h" |
1970 |
11 May 09 |
peter |
39 |
#include "DataWeight.h" |
2210 |
05 Mar 10 |
peter |
40 |
#include "Exception.h" |
4349 |
19 Jul 23 |
peter |
41 |
#include "yat_assert.h" |
1970 |
11 May 09 |
peter |
42 |
|
2202 |
21 Feb 10 |
peter |
43 |
#include <boost/concept_check.hpp> |
1399 |
06 Aug 08 |
peter |
44 |
#include <boost/iterator/transform_iterator.hpp> |
1399 |
06 Aug 08 |
peter |
45 |
#include <boost/mpl/if.hpp> |
2068 |
17 Sep 09 |
peter |
46 |
#include <boost/type_traits/add_const.hpp> |
1399 |
06 Aug 08 |
peter |
47 |
#include <boost/type_traits/is_const.hpp> |
2068 |
17 Sep 09 |
peter |
48 |
#include <boost/type_traits/remove_reference.hpp> |
1399 |
06 Aug 08 |
peter |
49 |
|
869 |
14 Sep 07 |
peter |
50 |
#include <algorithm> |
1288 |
24 Apr 08 |
peter |
51 |
#include <cmath> |
2181 |
02 Feb 10 |
peter |
52 |
#include <exception> |
1003 |
18 Jan 08 |
peter |
53 |
#include <functional> |
2285 |
27 Jun 10 |
peter |
54 |
#include <iterator> |
1385 |
22 Jul 08 |
peter |
55 |
#include <map> |
675 |
10 Oct 06 |
jari |
56 |
#include <ostream> |
2181 |
02 Feb 10 |
peter |
57 |
#include <sstream> |
262 |
07 Apr 05 |
peter |
58 |
#include <string> |
58 |
14 Apr 04 |
jari |
59 |
#include <utility> |
1385 |
22 Jul 08 |
peter |
60 |
#include <vector> |
58 |
14 Apr 04 |
jari |
61 |
|
2010 |
27 Jun 09 |
peter |
// We are intruding standard namespace, which might cause |
2010 |
27 Jun 09 |
peter |
// conflicts. Let the user turn off these declarations by defining |
2010 |
27 Jun 09 |
peter |
// YAT_STD_DISABE |
2010 |
27 Jun 09 |
peter |
65 |
#ifndef YAT_STD_DISABLE |
432 |
13 Dec 05 |
markus |
66 |
namespace std { |
437 |
15 Dec 05 |
jari |
67 |
|
432 |
13 Dec 05 |
markus |
68 |
/// |
2730 |
24 Apr 12 |
peter |
/// Print out a pair |
432 |
13 Dec 05 |
markus |
70 |
/// |
432 |
13 Dec 05 |
markus |
// This is in namespace std because we have not figured out how to have |
432 |
13 Dec 05 |
markus |
// pair and its operator<< in different namespaces |
2730 |
24 Apr 12 |
peter |
73 |
template <class T1, class T2> |
2730 |
24 Apr 12 |
peter |
74 |
std::ostream& operator<<(std::ostream& out, const std::pair<T1,T2>& p) |
432 |
13 Dec 05 |
markus |
75 |
{ out << p.first << "\t" << p.second; return out; } |
437 |
15 Dec 05 |
jari |
76 |
|
432 |
13 Dec 05 |
markus |
77 |
} |
2010 |
27 Jun 09 |
peter |
78 |
#endif |
432 |
13 Dec 05 |
markus |
79 |
|
58 |
14 Apr 04 |
jari |
80 |
namespace theplu { |
680 |
11 Oct 06 |
jari |
81 |
namespace yat { |
301 |
30 Apr 05 |
peter |
82 |
namespace utility { |
58 |
14 Apr 04 |
jari |
83 |
|
869 |
14 Sep 07 |
peter |
84 |
/** |
1003 |
18 Jan 08 |
peter |
Functor class taking absolute value |
1003 |
18 Jan 08 |
peter |
86 |
*/ |
1003 |
18 Jan 08 |
peter |
87 |
template<typename T> |
4339 |
15 Apr 23 |
peter |
88 |
struct abs |
1003 |
18 Jan 08 |
peter |
89 |
{ |
4339 |
15 Apr 23 |
peter |
/// \c argument_type is \c T |
4339 |
15 Apr 23 |
peter |
91 |
typedef T argument_type; |
4339 |
15 Apr 23 |
peter |
92 |
|
4339 |
15 Apr 23 |
peter |
/// \c result_type is \c T |
4339 |
15 Apr 23 |
peter |
94 |
typedef T result_type; |
4339 |
15 Apr 23 |
peter |
95 |
|
1003 |
18 Jan 08 |
peter |
96 |
/** |
1003 |
18 Jan 08 |
peter |
\return absolute value |
1003 |
18 Jan 08 |
peter |
98 |
*/ |
1003 |
18 Jan 08 |
peter |
99 |
inline T operator()(T x) const |
1003 |
18 Jan 08 |
peter |
100 |
{ return std::abs(x); } |
1003 |
18 Jan 08 |
peter |
101 |
}; |
1003 |
18 Jan 08 |
peter |
102 |
|
1786 |
09 Feb 09 |
peter |
103 |
|
1003 |
18 Jan 08 |
peter |
104 |
/** |
2285 |
27 Jun 10 |
peter |
\brief Adaptor between pointer and pointee interface |
2285 |
27 Jun 10 |
peter |
106 |
|
2730 |
24 Apr 12 |
peter |
Functor takes a pointer and returns a reference to the instance |
2730 |
24 Apr 12 |
peter |
pointer is pointing to. Return type is decided by <a |
2730 |
24 Apr 12 |
peter |
href=http://www.sgi.com/tech/stl/iterator_traits.html> |
2730 |
24 Apr 12 |
peter |
std::iterator_traits<Pointer>::reference </a>. Pointer must have |
2730 |
24 Apr 12 |
peter |
an \c operator*, i.e., \c Pointer can be a traditional pointer or |
2730 |
24 Apr 12 |
peter |
an \input_iterator. |
2286 |
27 Jun 10 |
peter |
113 |
|
2730 |
24 Apr 12 |
peter |
The class is designed to be used with boost::transform_iterator |
2730 |
24 Apr 12 |
peter |
115 |
|
2730 |
24 Apr 12 |
peter |
\code |
2730 |
24 Apr 12 |
peter |
std::vector<MyClass*> vec; |
2730 |
24 Apr 12 |
peter |
118 |
... |
2730 |
24 Apr 12 |
peter |
Dereferencer<MyClass*> dereferencer; |
2731 |
30 Apr 12 |
peter |
std::set<MyClass> s; |
2731 |
30 Apr 12 |
peter |
s.insert(boost::make_transform_iterator(vec.begin(), dereferencer), |
2731 |
30 Apr 12 |
peter |
boost::make_transform_iterator(vec.end(), dereferencer)) |
2730 |
24 Apr 12 |
peter |
\endcode |
2730 |
24 Apr 12 |
peter |
124 |
|
2731 |
30 Apr 12 |
peter |
where elements in vec<MyClass*> are copied in to set<MyClass>. |
2730 |
24 Apr 12 |
peter |
126 |
|
2286 |
27 Jun 10 |
peter |
\since New in yat 0.7 |
2285 |
27 Jun 10 |
peter |
128 |
*/ |
2285 |
27 Jun 10 |
peter |
129 |
template<typename Pointer> |
4339 |
15 Apr 23 |
peter |
130 |
struct Dereferencer |
2285 |
27 Jun 10 |
peter |
131 |
{ |
4339 |
15 Apr 23 |
peter |
/// \c argument_type is \c Pointer |
4339 |
15 Apr 23 |
peter |
133 |
typedef Pointer argument_type; |
4339 |
15 Apr 23 |
peter |
/// \c result_type |
4339 |
15 Apr 23 |
peter |
135 |
typedef typename std::iterator_traits<Pointer>::reference result_type; |
4339 |
15 Apr 23 |
peter |
136 |
|
2285 |
27 Jun 10 |
peter |
137 |
/** |
2286 |
27 Jun 10 |
peter |
\brief constructor |
2286 |
27 Jun 10 |
peter |
139 |
*/ |
2730 |
24 Apr 12 |
peter |
140 |
Dereferencer(void) |
2286 |
27 Jun 10 |
peter |
141 |
{ BOOST_CONCEPT_ASSERT((TrivialIterator<Pointer>)); } |
2286 |
27 Jun 10 |
peter |
142 |
|
2286 |
27 Jun 10 |
peter |
143 |
/** |
2285 |
27 Jun 10 |
peter |
\return * \a ti |
2285 |
27 Jun 10 |
peter |
145 |
*/ |
2285 |
27 Jun 10 |
peter |
146 |
typename std::iterator_traits<Pointer>::reference |
2285 |
27 Jun 10 |
peter |
147 |
operator()(Pointer ti) const { return *ti; } |
2285 |
27 Jun 10 |
peter |
148 |
}; |
2285 |
27 Jun 10 |
peter |
149 |
|
2285 |
27 Jun 10 |
peter |
150 |
|
2285 |
27 Jun 10 |
peter |
151 |
/** |
1003 |
18 Jan 08 |
peter |
See The C++ Standard Library - A Tutorial and Reference by |
1003 |
18 Jan 08 |
peter |
Nicolai M. Josuttis |
1003 |
18 Jan 08 |
peter |
154 |
|
1003 |
18 Jan 08 |
peter |
If f is a binary functor, both g and h are unary functors, and |
1003 |
18 Jan 08 |
peter |
return type of g (and h) is convertible to F's argument type, |
1003 |
18 Jan 08 |
peter |
then compose_f_gx_hy can be used to create a functor equivalent |
1003 |
18 Jan 08 |
peter |
to \f$ f(g(x), h(y)) \f$ |
2001 |
13 Jun 09 |
peter |
159 |
|
2275 |
22 Jun 10 |
peter |
- F must be an <a |
2275 |
22 Jun 10 |
peter |
href="http://www.sgi.com/tech/stl/AdaptableBinaryFunction.html"> |
2275 |
22 Jun 10 |
peter |
AdaptableBinaryFunction</a> |
2275 |
22 Jun 10 |
peter |
- G must be an <a |
2275 |
22 Jun 10 |
peter |
href="http://www.sgi.com/tech/stl/AdaptableUnaryFunction.html"> |
2730 |
24 Apr 12 |
peter |
AdaptableUnaryFunction</a> |
2275 |
22 Jun 10 |
peter |
- H must be an <a |
2275 |
22 Jun 10 |
peter |
href="http://www.sgi.com/tech/stl/AdaptableUnaryFunction.html"> |
4200 |
19 Aug 22 |
peter |
AdaptableUnaryFunction</a> |
2275 |
22 Jun 10 |
peter |
- \c G::result_type is convertible to \c F::first_argument_type |
2275 |
22 Jun 10 |
peter |
- \c H::result_type is convertible to \c F::second_argument_type |
2275 |
22 Jun 10 |
peter |
171 |
|
3082 |
18 Sep 13 |
peter |
\see compose_f_gxy, compose_f_gx, and compose_f_gx_hx |
3466 |
10 Feb 16 |
peter |
173 |
|
3466 |
10 Feb 16 |
peter |
Here is an example using the class to construct a functor that |
3466 |
10 Feb 16 |
peter |
compares std::pairs ignoring \c second. |
3466 |
10 Feb 16 |
peter |
176 |
|
3466 |
10 Feb 16 |
peter |
\code |
3466 |
10 Feb 16 |
peter |
vector<pair<string, foo> > data; |
3466 |
10 Feb 16 |
peter |
data.push_back(make_pair("Orange", foo(2)); |
3466 |
10 Feb 16 |
peter |
data.push_back(make_pair("Orange", foo(1)); |
3466 |
10 Feb 16 |
peter |
data.push_back(make_pair("Apple", foo(10)); |
3466 |
10 Feb 16 |
peter |
typedef PairFirst<const pair<string, foo> > PF; |
3466 |
10 Feb 16 |
peter |
compose_f_gx_hy<less<string>, PF, PF> compare; |
3466 |
10 Feb 16 |
peter |
sort(data.begin(), data.end(), compare); |
3466 |
10 Feb 16 |
peter |
\endcode |
3466 |
10 Feb 16 |
peter |
186 |
|
1003 |
18 Jan 08 |
peter |
187 |
*/ |
1003 |
18 Jan 08 |
peter |
188 |
template<class F, class G, class H> |
4339 |
15 Apr 23 |
peter |
189 |
class compose_f_gx_hy |
1003 |
18 Jan 08 |
peter |
190 |
{ |
1003 |
18 Jan 08 |
peter |
191 |
public: |
4339 |
15 Apr 23 |
peter |
/// \c first_argument_type is G's \c argument_type |
4339 |
15 Apr 23 |
peter |
193 |
typedef typename G::argument_type first_argument_type; |
4339 |
15 Apr 23 |
peter |
/// \c second_argument_type is H's \c argument_type |
4339 |
15 Apr 23 |
peter |
195 |
typedef typename H::argument_type second_argument_type; |
4339 |
15 Apr 23 |
peter |
/// \c result_type is F's \c result_type |
4339 |
15 Apr 23 |
peter |
197 |
typedef typename F::result_type result_type; |
4339 |
15 Apr 23 |
peter |
198 |
|
1003 |
18 Jan 08 |
peter |
199 |
/** |
2963 |
21 Jan 13 |
peter |
\brief default constructor |
2963 |
21 Jan 13 |
peter |
201 |
|
2963 |
21 Jan 13 |
peter |
Requires that F, G, and H have default constructors |
2963 |
21 Jan 13 |
peter |
203 |
*/ |
2963 |
21 Jan 13 |
peter |
204 |
compose_f_gx_hy(void) {} |
2963 |
21 Jan 13 |
peter |
205 |
|
2963 |
21 Jan 13 |
peter |
206 |
/** |
1003 |
18 Jan 08 |
peter |
\brief Constructor |
1003 |
18 Jan 08 |
peter |
208 |
*/ |
1003 |
18 Jan 08 |
peter |
209 |
compose_f_gx_hy(F f, G g, H h) |
2730 |
24 Apr 12 |
peter |
210 |
: f_(f), g_(g), h_(h) |
2274 |
22 Jun 10 |
peter |
211 |
{ |
2274 |
22 Jun 10 |
peter |
212 |
} |
2274 |
22 Jun 10 |
peter |
213 |
|
1003 |
18 Jan 08 |
peter |
214 |
/** |
1003 |
18 Jan 08 |
peter |
\brief Does the work |
1003 |
18 Jan 08 |
peter |
216 |
*/ |
3083 |
19 Sep 13 |
peter |
217 |
typename F::result_type operator()(typename G::argument_type x, |
3083 |
19 Sep 13 |
peter |
218 |
typename H::argument_type y) const |
1003 |
18 Jan 08 |
peter |
219 |
{ |
1003 |
18 Jan 08 |
peter |
220 |
return f_(g_(x), h_(y)); |
1003 |
18 Jan 08 |
peter |
221 |
} |
1003 |
18 Jan 08 |
peter |
222 |
|
1003 |
18 Jan 08 |
peter |
223 |
private: |
1003 |
18 Jan 08 |
peter |
224 |
F f_; |
1003 |
18 Jan 08 |
peter |
225 |
G g_; |
1003 |
18 Jan 08 |
peter |
226 |
H h_; |
1003 |
18 Jan 08 |
peter |
227 |
}; |
1003 |
18 Jan 08 |
peter |
228 |
|
1003 |
18 Jan 08 |
peter |
229 |
/** |
1003 |
18 Jan 08 |
peter |
Convenient function to create a compose_f_gx_hy. |
1003 |
18 Jan 08 |
peter |
231 |
|
2274 |
22 Jun 10 |
peter |
\relates compose_f_gx_hy |
2274 |
22 Jun 10 |
peter |
233 |
|
1003 |
18 Jan 08 |
peter |
\see std::make_pair |
1003 |
18 Jan 08 |
peter |
235 |
*/ |
1003 |
18 Jan 08 |
peter |
236 |
template<class F, class G, class H> |
1003 |
18 Jan 08 |
peter |
237 |
compose_f_gx_hy<F, G, H> make_compose_f_gx_hy(F f, G g, H h) |
1003 |
18 Jan 08 |
peter |
238 |
{ |
1003 |
18 Jan 08 |
peter |
239 |
return compose_f_gx_hy<F,G,H>(f,g,h); |
2730 |
24 Apr 12 |
peter |
240 |
} |
1003 |
18 Jan 08 |
peter |
241 |
|
2274 |
22 Jun 10 |
peter |
242 |
|
1003 |
18 Jan 08 |
peter |
243 |
/** |
2274 |
22 Jun 10 |
peter |
See The C++ Standard Library - A Tutorial and Reference by |
2274 |
22 Jun 10 |
peter |
Nicolai M. Josuttis |
2274 |
22 Jun 10 |
peter |
246 |
|
2274 |
22 Jun 10 |
peter |
If f is a unary functor, g is a binary functor, and return type |
2274 |
22 Jun 10 |
peter |
of g is convertible to F's argument type, then |
2274 |
22 Jun 10 |
peter |
compose_f_gxy can be used to create a functor equivalent to |
2274 |
22 Jun 10 |
peter |
\f$ f(g(x,y)) \f$ |
2274 |
22 Jun 10 |
peter |
251 |
|
2275 |
22 Jun 10 |
peter |
- F must be an <a |
2275 |
22 Jun 10 |
peter |
href="http://www.sgi.com/tech/stl/AdaptableUnaryFunction.html"> |
2275 |
22 Jun 10 |
peter |
AdaptableUnaryFunction</a> |
2275 |
22 Jun 10 |
peter |
- G must be an <a |
2275 |
22 Jun 10 |
peter |
href="http://www.sgi.com/tech/stl/AdaptableBinaryFunction.html"> |
2730 |
24 Apr 12 |
peter |
AdaptableBinaryFunction</a> |
2275 |
22 Jun 10 |
peter |
- \c G::result_type is convertible to \c F::argument_type |
2274 |
22 Jun 10 |
peter |
259 |
|
3082 |
18 Sep 13 |
peter |
\see compose_f_gx_hy, compose_f_gx, and compose_f_gx_hx |
2275 |
22 Jun 10 |
peter |
261 |
|
2274 |
22 Jun 10 |
peter |
\since New in yat 0.7 |
2274 |
22 Jun 10 |
peter |
263 |
*/ |
2274 |
22 Jun 10 |
peter |
264 |
template<class F, class G> |
4339 |
15 Apr 23 |
peter |
265 |
class compose_f_gxy |
2274 |
22 Jun 10 |
peter |
266 |
{ |
2274 |
22 Jun 10 |
peter |
267 |
public: |
4339 |
15 Apr 23 |
peter |
/// \c first_argument_type is G's first_argument_type |
4339 |
15 Apr 23 |
peter |
269 |
typedef typename G::first_argument_type first_argument_type; |
4339 |
15 Apr 23 |
peter |
/// \c second_argument_type is G's second_argument_type |
4339 |
15 Apr 23 |
peter |
271 |
typedef typename G::second_argument_type second_argument_type; |
4339 |
15 Apr 23 |
peter |
/// \c result_type is F's result_type |
4339 |
15 Apr 23 |
peter |
273 |
typedef typename F::result_type result_type; |
4339 |
15 Apr 23 |
peter |
274 |
|
2274 |
22 Jun 10 |
peter |
275 |
/** |
2963 |
21 Jan 13 |
peter |
\brief default constructor |
2963 |
21 Jan 13 |
peter |
277 |
|
2963 |
21 Jan 13 |
peter |
Requires that F, G, and H have default constructors |
2963 |
21 Jan 13 |
peter |
279 |
*/ |
2963 |
21 Jan 13 |
peter |
280 |
compose_f_gxy(void) {} |
2963 |
21 Jan 13 |
peter |
281 |
|
2963 |
21 Jan 13 |
peter |
282 |
/** |
2274 |
22 Jun 10 |
peter |
\brief Constructor |
2274 |
22 Jun 10 |
peter |
284 |
*/ |
2274 |
22 Jun 10 |
peter |
285 |
compose_f_gxy(F f, G g) |
2730 |
24 Apr 12 |
peter |
286 |
: f_(f), g_(g) |
2274 |
22 Jun 10 |
peter |
287 |
{ |
2274 |
22 Jun 10 |
peter |
288 |
} |
2274 |
22 Jun 10 |
peter |
289 |
|
2274 |
22 Jun 10 |
peter |
290 |
/** |
2274 |
22 Jun 10 |
peter |
\brief Does the work |
2274 |
22 Jun 10 |
peter |
292 |
*/ |
2274 |
22 Jun 10 |
peter |
293 |
typename F::result_type |
2730 |
24 Apr 12 |
peter |
294 |
operator()(typename G::first_argument_type x, |
2274 |
22 Jun 10 |
peter |
295 |
typename G::second_argument_type y) const |
2274 |
22 Jun 10 |
peter |
296 |
{ |
2274 |
22 Jun 10 |
peter |
297 |
return f_(g_(x,y)); |
2274 |
22 Jun 10 |
peter |
298 |
} |
2274 |
22 Jun 10 |
peter |
299 |
|
2274 |
22 Jun 10 |
peter |
300 |
private: |
2274 |
22 Jun 10 |
peter |
301 |
F f_; |
2274 |
22 Jun 10 |
peter |
302 |
G g_; |
2274 |
22 Jun 10 |
peter |
303 |
}; |
2274 |
22 Jun 10 |
peter |
304 |
|
2274 |
22 Jun 10 |
peter |
305 |
/** |
2274 |
22 Jun 10 |
peter |
Convenient function to create a compose_f_gxy. |
2274 |
22 Jun 10 |
peter |
307 |
|
2274 |
22 Jun 10 |
peter |
\relates compose_f_gxy |
2274 |
22 Jun 10 |
peter |
309 |
|
2274 |
22 Jun 10 |
peter |
\see std::make_pair |
2274 |
22 Jun 10 |
peter |
311 |
|
2274 |
22 Jun 10 |
peter |
\since New in yat 0.7 |
2274 |
22 Jun 10 |
peter |
313 |
*/ |
2274 |
22 Jun 10 |
peter |
314 |
template<class F, class G> |
2274 |
22 Jun 10 |
peter |
315 |
compose_f_gxy<F, G> make_compose_f_gxy(F f, G g) |
2274 |
22 Jun 10 |
peter |
316 |
{ |
2274 |
22 Jun 10 |
peter |
317 |
return compose_f_gxy<F,G>(f,g); |
2730 |
24 Apr 12 |
peter |
318 |
} |
2274 |
22 Jun 10 |
peter |
319 |
|
2274 |
22 Jun 10 |
peter |
320 |
|
2274 |
22 Jun 10 |
peter |
321 |
/** |
2274 |
22 Jun 10 |
peter |
See The C++ Standard Library - A Tutorial and Reference by |
2274 |
22 Jun 10 |
peter |
Nicolai M. Josuttis |
2274 |
22 Jun 10 |
peter |
324 |
|
2274 |
22 Jun 10 |
peter |
If f is a unary functor, g is a unary functor, and return type of |
2274 |
22 Jun 10 |
peter |
g is convertible to F's argument type, then compose_f_gx can be |
2274 |
22 Jun 10 |
peter |
used to create a functor equivalent to \f$ f(g(x)) \f$ |
2274 |
22 Jun 10 |
peter |
328 |
|
2275 |
22 Jun 10 |
peter |
- F must be an <a |
2275 |
22 Jun 10 |
peter |
href="http://www.sgi.com/tech/stl/AdaptableBinaryFunction.html"> |
2275 |
22 Jun 10 |
peter |
AdaptableBinaryFunction</a> |
2275 |
22 Jun 10 |
peter |
- G must be an <a |
2275 |
22 Jun 10 |
peter |
href="http://www.sgi.com/tech/stl/AdaptableUnaryFunction.html"> |
2730 |
24 Apr 12 |
peter |
AdaptableUnaryFunction</a> |
2275 |
22 Jun 10 |
peter |
- \c G::result_type is convertible to \c F::argument_type |
2274 |
22 Jun 10 |
peter |
336 |
|
3082 |
18 Sep 13 |
peter |
\see compose_f_gx_hy, compose_f_gxy, and compose_f_gx_hx |
2275 |
22 Jun 10 |
peter |
338 |
|
3082 |
18 Sep 13 |
peter |
\see <a href="http://www.sgi.com/tech/stl/unary_compose.html"> |
3082 |
18 Sep 13 |
peter |
unary_compose</a> (SGI extension) |
3082 |
18 Sep 13 |
peter |
341 |
|
2274 |
22 Jun 10 |
peter |
\since New in yat 0.7 |
2274 |
22 Jun 10 |
peter |
343 |
*/ |
2274 |
22 Jun 10 |
peter |
344 |
template<class F, class G> |
4339 |
15 Apr 23 |
peter |
345 |
class compose_f_gx |
2274 |
22 Jun 10 |
peter |
346 |
{ |
2274 |
22 Jun 10 |
peter |
347 |
public: |
4339 |
15 Apr 23 |
peter |
/// \c argument_type is G's \c argument_type |
4339 |
15 Apr 23 |
peter |
349 |
typedef typename G::argument_type argument_type; |
4339 |
15 Apr 23 |
peter |
/// \c result_type is G's \c result_type |
4339 |
15 Apr 23 |
peter |
351 |
typedef typename F::result_type result_type; |
4339 |
15 Apr 23 |
peter |
352 |
|
2274 |
22 Jun 10 |
peter |
353 |
/** |
2963 |
21 Jan 13 |
peter |
\brief default constructor |
2963 |
21 Jan 13 |
peter |
355 |
|
3082 |
18 Sep 13 |
peter |
Requires that F and G have default constructors |
2963 |
21 Jan 13 |
peter |
357 |
*/ |
2963 |
21 Jan 13 |
peter |
358 |
compose_f_gx(void) {} |
2963 |
21 Jan 13 |
peter |
359 |
|
2963 |
21 Jan 13 |
peter |
360 |
/** |
2274 |
22 Jun 10 |
peter |
\brief Constructor |
2274 |
22 Jun 10 |
peter |
362 |
*/ |
2274 |
22 Jun 10 |
peter |
363 |
compose_f_gx(F f, G g) |
2730 |
24 Apr 12 |
peter |
364 |
: f_(f), g_(g) |
2274 |
22 Jun 10 |
peter |
365 |
{ |
2274 |
22 Jun 10 |
peter |
366 |
} |
2274 |
22 Jun 10 |
peter |
367 |
|
2274 |
22 Jun 10 |
peter |
368 |
/** |
2274 |
22 Jun 10 |
peter |
\brief Does the work |
2274 |
22 Jun 10 |
peter |
370 |
*/ |
2274 |
22 Jun 10 |
peter |
371 |
typename F::result_type |
2274 |
22 Jun 10 |
peter |
372 |
operator()(typename G::argument_type x) const |
2274 |
22 Jun 10 |
peter |
373 |
{ |
2274 |
22 Jun 10 |
peter |
374 |
return f_(g_(x)); |
2274 |
22 Jun 10 |
peter |
375 |
} |
2274 |
22 Jun 10 |
peter |
376 |
|
2274 |
22 Jun 10 |
peter |
377 |
private: |
2274 |
22 Jun 10 |
peter |
378 |
F f_; |
2274 |
22 Jun 10 |
peter |
379 |
G g_; |
2274 |
22 Jun 10 |
peter |
380 |
}; |
2274 |
22 Jun 10 |
peter |
381 |
|
2274 |
22 Jun 10 |
peter |
382 |
/** |
2274 |
22 Jun 10 |
peter |
Convenient function to create a compose_f_gx. |
2274 |
22 Jun 10 |
peter |
384 |
|
2274 |
22 Jun 10 |
peter |
\relates compose_f_gx |
2274 |
22 Jun 10 |
peter |
386 |
|
2274 |
22 Jun 10 |
peter |
\see std::make_pair |
2274 |
22 Jun 10 |
peter |
388 |
|
2274 |
22 Jun 10 |
peter |
\since New in yat 0.7 |
2274 |
22 Jun 10 |
peter |
390 |
*/ |
2274 |
22 Jun 10 |
peter |
391 |
template<class F, class G> |
2274 |
22 Jun 10 |
peter |
392 |
compose_f_gx<F, G> make_compose_f_gx(F f, G g) |
2274 |
22 Jun 10 |
peter |
393 |
{ |
2274 |
22 Jun 10 |
peter |
394 |
return compose_f_gx<F,G>(f,g); |
2730 |
24 Apr 12 |
peter |
395 |
} |
2274 |
22 Jun 10 |
peter |
396 |
|
2274 |
22 Jun 10 |
peter |
397 |
|
2274 |
22 Jun 10 |
peter |
398 |
/** |
3084 |
19 Sep 13 |
peter |
If f is a binary functor, g and h a unary functors, return |
3084 |
19 Sep 13 |
peter |
type of g is convertible to F's first argument type, and return |
3084 |
19 Sep 13 |
peter |
type of h is convertible to F's second argument type, then |
3082 |
18 Sep 13 |
peter |
compose_f_gx_hx can be used to create a functor equivalent to \f$ |
3082 |
18 Sep 13 |
peter |
f(g(x), h(x)) \f$ |
3082 |
18 Sep 13 |
peter |
404 |
|
3082 |
18 Sep 13 |
peter |
- F must be an <a |
3082 |
18 Sep 13 |
peter |
href="http://www.sgi.com/tech/stl/AdaptableBinaryFunction.html"> |
3082 |
18 Sep 13 |
peter |
AdaptableBinaryFunction</a> |
3082 |
18 Sep 13 |
peter |
- G must be an <a |
3082 |
18 Sep 13 |
peter |
href="http://www.sgi.com/tech/stl/AdaptableUnaryFunction.html"> |
3082 |
18 Sep 13 |
peter |
AdaptableUnaryFunction</a> |
3082 |
18 Sep 13 |
peter |
- H must be an <a |
3082 |
18 Sep 13 |
peter |
href="http://www.sgi.com/tech/stl/AdaptableUnaryFunction.html"> |
3082 |
18 Sep 13 |
peter |
AdaptableUnaryFunction</a> |
3082 |
18 Sep 13 |
peter |
- \c G::result_type is convertible to \c F::first_argument_type |
3082 |
18 Sep 13 |
peter |
- \c H::result_type is convertible to \c F::second_argument_type |
3082 |
18 Sep 13 |
peter |
416 |
|
3082 |
18 Sep 13 |
peter |
\see compose_f_gx_hy, compose_f_gxy, and compose_f_gx |
3082 |
18 Sep 13 |
peter |
418 |
|
3082 |
18 Sep 13 |
peter |
\see <a href="http://www.sgi.com/tech/stl/binary_compose.html"> |
3082 |
18 Sep 13 |
peter |
binary_compose</a> (SGI extension) |
3082 |
18 Sep 13 |
peter |
421 |
|
3082 |
18 Sep 13 |
peter |
\since New in yat 0.11 |
3082 |
18 Sep 13 |
peter |
423 |
*/ |
3082 |
18 Sep 13 |
peter |
424 |
template<class F, class G, class H> |
4339 |
15 Apr 23 |
peter |
425 |
class compose_f_gx_hx |
3082 |
18 Sep 13 |
peter |
426 |
{ |
3082 |
18 Sep 13 |
peter |
427 |
public: |
4339 |
15 Apr 23 |
peter |
/// \c argument_type is G's \c argument_type |
4339 |
15 Apr 23 |
peter |
429 |
typedef typename G::argument_type argument_type; |
4339 |
15 Apr 23 |
peter |
/// \c result_type is F's \c result_type |
4339 |
15 Apr 23 |
peter |
431 |
typedef typename F::result_type result_type; |
4339 |
15 Apr 23 |
peter |
432 |
|
3082 |
18 Sep 13 |
peter |
433 |
/** |
3082 |
18 Sep 13 |
peter |
\brief default constructor |
3082 |
18 Sep 13 |
peter |
435 |
|
3082 |
18 Sep 13 |
peter |
Requires that F, G, and H have default constructors |
3082 |
18 Sep 13 |
peter |
437 |
*/ |
3082 |
18 Sep 13 |
peter |
438 |
compose_f_gx_hx(void) {} |
3082 |
18 Sep 13 |
peter |
439 |
|
3082 |
18 Sep 13 |
peter |
440 |
/** |
3082 |
18 Sep 13 |
peter |
\brief Constructor |
3082 |
18 Sep 13 |
peter |
442 |
*/ |
3082 |
18 Sep 13 |
peter |
443 |
compose_f_gx_hx(F f, G g, H h) |
3082 |
18 Sep 13 |
peter |
444 |
: f_(f), g_(g), h_(h) |
3082 |
18 Sep 13 |
peter |
445 |
{ |
3082 |
18 Sep 13 |
peter |
446 |
} |
3082 |
18 Sep 13 |
peter |
447 |
|
3082 |
18 Sep 13 |
peter |
448 |
/** |
3082 |
18 Sep 13 |
peter |
\brief Does the work |
3082 |
18 Sep 13 |
peter |
450 |
*/ |
3083 |
19 Sep 13 |
peter |
451 |
typename F::result_type operator()(typename G::argument_type x) const |
3082 |
18 Sep 13 |
peter |
452 |
{ |
3082 |
18 Sep 13 |
peter |
453 |
return f_(g_(x), h_(x)); |
3082 |
18 Sep 13 |
peter |
454 |
} |
3082 |
18 Sep 13 |
peter |
455 |
|
3082 |
18 Sep 13 |
peter |
456 |
private: |
3082 |
18 Sep 13 |
peter |
457 |
F f_; |
3082 |
18 Sep 13 |
peter |
458 |
G g_; |
3082 |
18 Sep 13 |
peter |
459 |
H h_; |
3082 |
18 Sep 13 |
peter |
460 |
}; |
3082 |
18 Sep 13 |
peter |
461 |
|
3082 |
18 Sep 13 |
peter |
462 |
/** |
3082 |
18 Sep 13 |
peter |
Convenient function to create a compose_f_gx_hx. |
3082 |
18 Sep 13 |
peter |
464 |
|
3082 |
18 Sep 13 |
peter |
\relates compose_f_gx_hx |
3082 |
18 Sep 13 |
peter |
466 |
|
3082 |
18 Sep 13 |
peter |
\see std::make_pair |
3082 |
18 Sep 13 |
peter |
468 |
|
3082 |
18 Sep 13 |
peter |
\since New in yat 0.11 |
3082 |
18 Sep 13 |
peter |
470 |
*/ |
3082 |
18 Sep 13 |
peter |
471 |
template<class F, class G, class H> |
3082 |
18 Sep 13 |
peter |
472 |
compose_f_gx_hx<F, G, H> make_compose_f_gx_hx(F f, G g, H h) |
3082 |
18 Sep 13 |
peter |
473 |
{ |
3082 |
18 Sep 13 |
peter |
474 |
return compose_f_gx_hx<F,G,H>(f,g,h); |
3082 |
18 Sep 13 |
peter |
475 |
} |
3082 |
18 Sep 13 |
peter |
476 |
|
3082 |
18 Sep 13 |
peter |
477 |
|
3082 |
18 Sep 13 |
peter |
478 |
/** |
1288 |
24 Apr 08 |
peter |
Functor class to exponentiate values using std::exp |
1339 |
06 Jun 08 |
peter |
480 |
|
1998 |
13 Jun 09 |
peter |
T should be either \c float, \c double, or \c long \c double |
1998 |
13 Jun 09 |
peter |
482 |
|
1339 |
06 Jun 08 |
peter |
\since New in yat 0.5 |
1288 |
24 Apr 08 |
peter |
484 |
*/ |
1288 |
24 Apr 08 |
peter |
485 |
template<typename T> |
4339 |
15 Apr 23 |
peter |
486 |
struct Exp |
1288 |
24 Apr 08 |
peter |
487 |
{ |
4339 |
15 Apr 23 |
peter |
/// \c argument_type is \c T |
4339 |
15 Apr 23 |
peter |
489 |
typedef T argument_type; |
4339 |
15 Apr 23 |
peter |
/// \c result_type is \c T |
4339 |
15 Apr 23 |
peter |
491 |
typedef T result_type; |
4339 |
15 Apr 23 |
peter |
492 |
|
1288 |
24 Apr 08 |
peter |
493 |
/** |
1341 |
17 Jun 08 |
peter |
\return exponentiated value |
1288 |
24 Apr 08 |
peter |
495 |
*/ |
1288 |
24 Apr 08 |
peter |
496 |
inline T operator()(T x) const |
1288 |
24 Apr 08 |
peter |
497 |
{ return std::exp(x); } |
1288 |
24 Apr 08 |
peter |
498 |
}; |
1288 |
24 Apr 08 |
peter |
499 |
|
1288 |
24 Apr 08 |
peter |
500 |
/** |
2359 |
02 Dec 10 |
peter |
\brief Identity functor that returns its argument |
2359 |
02 Dec 10 |
peter |
502 |
|
2359 |
02 Dec 10 |
peter |
\since New in yat 0.7 |
2359 |
02 Dec 10 |
peter |
504 |
*/ |
2359 |
02 Dec 10 |
peter |
505 |
template<typename T> |
4339 |
15 Apr 23 |
peter |
506 |
struct Identity |
2359 |
02 Dec 10 |
peter |
507 |
{ |
4339 |
15 Apr 23 |
peter |
/// \c argument_type is \c T |
4339 |
15 Apr 23 |
peter |
509 |
typedef T argument_type; |
4339 |
15 Apr 23 |
peter |
/// \c result_type is \c T |
4339 |
15 Apr 23 |
peter |
511 |
typedef T result_type; |
2359 |
02 Dec 10 |
peter |
/// \return \a arg |
2359 |
02 Dec 10 |
peter |
513 |
T operator()(T arg) const { return arg; } |
2359 |
02 Dec 10 |
peter |
514 |
}; |
2359 |
02 Dec 10 |
peter |
515 |
|
2359 |
02 Dec 10 |
peter |
516 |
|
2359 |
02 Dec 10 |
peter |
517 |
/** |
3404 |
03 Apr 15 |
peter |
\brief reduce size and capacity to zero |
3404 |
03 Apr 15 |
peter |
519 |
|
4324 |
03 Mar 23 |
peter |
In C++11 it's typically easier to call vector::clear() followed |
4324 |
03 Mar 23 |
peter |
by vector::shrink_to_fit(), which gives the same result. |
3404 |
03 Apr 15 |
peter |
522 |
|
3404 |
03 Apr 15 |
peter |
\since new in yat 0.13 |
3404 |
03 Apr 15 |
peter |
524 |
*/ |
3404 |
03 Apr 15 |
peter |
525 |
template<typename T> |
3404 |
03 Apr 15 |
peter |
526 |
void clear(std::vector<T>& vec) |
3404 |
03 Apr 15 |
peter |
527 |
{ |
3404 |
03 Apr 15 |
peter |
528 |
std::vector<T> other; |
3404 |
03 Apr 15 |
peter |
529 |
vec.swap(other); |
3404 |
03 Apr 15 |
peter |
530 |
} |
3404 |
03 Apr 15 |
peter |
531 |
|
3404 |
03 Apr 15 |
peter |
532 |
|
3404 |
03 Apr 15 |
peter |
533 |
/** |
2181 |
02 Feb 10 |
peter |
Same functionality as map::operator[] but the function does not |
2181 |
02 Feb 10 |
peter |
modify the map and the function throws if key does not exist in |
2181 |
02 Feb 10 |
peter |
the map. |
2181 |
02 Feb 10 |
peter |
537 |
|
3254 |
09 Jun 14 |
peter |
Type Requirment: |
3254 |
09 Jun 14 |
peter |
- \a Key2 is convertible to Key |
3254 |
09 Jun 14 |
peter |
540 |
|
2181 |
02 Feb 10 |
peter |
\return const reference to m[k] |
2181 |
02 Feb 10 |
peter |
542 |
|
3254 |
09 Jun 14 |
peter |
\throw get_error if key \a k does not exist in map \a m |
3253 |
07 Jun 14 |
peter |
544 |
|
3779 |
06 Dec 18 |
peter |
Similar to std::map::at(const Key& ) in c++11. |
3779 |
06 Dec 18 |
peter |
546 |
|
2220 |
15 Mar 10 |
peter |
\since New in yat 0.7 |
2181 |
02 Feb 10 |
peter |
548 |
*/ |
3254 |
09 Jun 14 |
peter |
549 |
template <typename Key, typename Tp, typename Compare, typename Alloc, |
3254 |
09 Jun 14 |
peter |
550 |
typename Key2> |
3254 |
09 Jun 14 |
peter |
551 |
const Tp& get(const std::map<Key, Tp, Compare, Alloc>& m, const Key2& k); |
2181 |
02 Feb 10 |
peter |
552 |
|
3253 |
07 Jun 14 |
peter |
553 |
/** |
3253 |
07 Jun 14 |
peter |
\brief error class used in |
3253 |
07 Jun 14 |
peter |
get(const std::map<Key, Tp, Compare, Alloc>& m, const Key& k) |
2181 |
02 Feb 10 |
peter |
556 |
|
3253 |
07 Jun 14 |
peter |
\since yat 0.13 |
3253 |
07 Jun 14 |
peter |
558 |
*/ |
3253 |
07 Jun 14 |
peter |
559 |
template<typename Key> |
3253 |
07 Jun 14 |
peter |
560 |
class get_error : public runtime_error |
3253 |
07 Jun 14 |
peter |
561 |
{ |
3253 |
07 Jun 14 |
peter |
562 |
public: |
3253 |
07 Jun 14 |
peter |
/// \brief constructor |
3253 |
07 Jun 14 |
peter |
564 |
get_error(const std::string& msg, const Key& key) |
3253 |
07 Jun 14 |
peter |
565 |
: runtime_error(msg), key_(key) {} |
3253 |
07 Jun 14 |
peter |
/// \brief destructor |
3253 |
07 Jun 14 |
peter |
567 |
virtual ~get_error(void) throw () {} |
3253 |
07 Jun 14 |
peter |
/// access the key object |
3253 |
07 Jun 14 |
peter |
569 |
const Key& key(void) const { return key_; } |
3253 |
07 Jun 14 |
peter |
570 |
private: |
3253 |
07 Jun 14 |
peter |
571 |
Key key_; |
3253 |
07 Jun 14 |
peter |
572 |
}; |
3253 |
07 Jun 14 |
peter |
573 |
|
4349 |
19 Jul 23 |
peter |
574 |
|
4349 |
19 Jul 23 |
peter |
/// \cond IGNORE_DOXYGEN |
4349 |
19 Jul 23 |
peter |
576 |
|
4349 |
19 Jul 23 |
peter |
// private stuff |
4349 |
19 Jul 23 |
peter |
578 |
namespace detail |
4349 |
19 Jul 23 |
peter |
579 |
{ |
4349 |
19 Jul 23 |
peter |
580 |
template<typename InputIterator, class Compare> |
4349 |
19 Jul 23 |
peter |
581 |
InputIterator is_sorted_until(InputIterator first, InputIterator last, |
4350 |
20 Jul 23 |
peter |
582 |
Compare com, |
4349 |
19 Jul 23 |
peter |
583 |
std::forward_iterator_tag cat) |
4349 |
19 Jul 23 |
peter |
584 |
{ |
4349 |
19 Jul 23 |
peter |
585 |
return std::is_sorted_until(first, last, com); |
4349 |
19 Jul 23 |
peter |
586 |
} |
4349 |
19 Jul 23 |
peter |
587 |
|
4349 |
19 Jul 23 |
peter |
588 |
|
4349 |
19 Jul 23 |
peter |
589 |
template<typename InputIterator, class Compare> |
4349 |
19 Jul 23 |
peter |
590 |
InputIterator is_sorted_until(InputIterator first, InputIterator last, |
4350 |
20 Jul 23 |
peter |
591 |
Compare comp, |
4349 |
19 Jul 23 |
peter |
592 |
std::input_iterator_tag cat) |
4349 |
19 Jul 23 |
peter |
593 |
{ |
4349 |
19 Jul 23 |
peter |
594 |
BOOST_CONCEPT_ASSERT((boost::InputIterator<InputIterator>)); |
4350 |
20 Jul 23 |
peter |
595 |
BOOST_CONCEPT_ASSERT((boost::CopyConstructible< |
4350 |
20 Jul 23 |
peter |
596 |
typename std::iterator_traits<InputIterator>::value_type>)); |
4350 |
20 Jul 23 |
peter |
597 |
BOOST_CONCEPT_ASSERT((boost::BinaryPredicate< |
4350 |
20 Jul 23 |
peter |
598 |
Compare, |
4350 |
20 Jul 23 |
peter |
599 |
typename std::iterator_traits<InputIterator>::value_type, |
4350 |
20 Jul 23 |
peter |
600 |
typename std::iterator_traits<InputIterator>::value_type>)); |
4349 |
19 Jul 23 |
peter |
601 |
|
4349 |
19 Jul 23 |
peter |
602 |
if (first == last) |
4349 |
19 Jul 23 |
peter |
603 |
return last; |
4349 |
19 Jul 23 |
peter |
604 |
|
4349 |
19 Jul 23 |
peter |
605 |
while (true) { |
4349 |
19 Jul 23 |
peter |
606 |
auto prev = *first; |
4349 |
19 Jul 23 |
peter |
607 |
++first; |
4349 |
19 Jul 23 |
peter |
608 |
if (first == last) |
4349 |
19 Jul 23 |
peter |
609 |
return last; |
4349 |
19 Jul 23 |
peter |
610 |
if (comp(*first, prev)) |
4349 |
19 Jul 23 |
peter |
611 |
return first; |
4349 |
19 Jul 23 |
peter |
612 |
} |
4349 |
19 Jul 23 |
peter |
613 |
return last; |
4349 |
19 Jul 23 |
peter |
614 |
} |
4349 |
19 Jul 23 |
peter |
615 |
} // end of detail namespace |
4349 |
19 Jul 23 |
peter |
/// \endcond |
4349 |
19 Jul 23 |
peter |
617 |
|
2181 |
02 Feb 10 |
peter |
618 |
/** |
4349 |
19 Jul 23 |
peter |
Same as is_sorted_until(2) but uses \c com instead of operator< |
4349 |
19 Jul 23 |
peter |
to compare elements. Consequently no need for value type to have |
4349 |
19 Jul 23 |
peter |
an operator<. |
4349 |
19 Jul 23 |
peter |
622 |
|
4349 |
19 Jul 23 |
peter |
\since New in yat 0.21 |
4349 |
19 Jul 23 |
peter |
624 |
*/ |
4349 |
19 Jul 23 |
peter |
625 |
template<typename InputIterator, class Compare> |
4349 |
19 Jul 23 |
peter |
626 |
InputIterator is_sorted_until(InputIterator first, InputIterator last, |
4350 |
20 Jul 23 |
peter |
627 |
Compare com) |
4349 |
19 Jul 23 |
peter |
628 |
{ |
4349 |
19 Jul 23 |
peter |
629 |
typename std::iterator_traits<InputIterator>::iterator_category cat; |
4349 |
19 Jul 23 |
peter |
630 |
return detail::is_sorted_until(first, last, com, cat); |
4349 |
19 Jul 23 |
peter |
631 |
} |
4349 |
19 Jul 23 |
peter |
632 |
|
4349 |
19 Jul 23 |
peter |
633 |
|
4349 |
19 Jul 23 |
peter |
634 |
/** |
4349 |
19 Jul 23 |
peter |
Same behaviour as <a |
4349 |
19 Jul 23 |
peter |
href=https://cplusplus.com/reference/algorithm/is_sorted_until/>std::is_sorted_until</a>, |
4349 |
19 Jul 23 |
peter |
but works also for \input_iterator. For \forward_iterator the |
4349 |
19 Jul 23 |
peter |
type requirements are the same as in std::is_sorted_until; for |
4349 |
19 Jul 23 |
peter |
\input_iterator, the value type is copy constructible and has an |
4349 |
19 Jul 23 |
peter |
operator<. |
4349 |
19 Jul 23 |
peter |
641 |
|
4349 |
19 Jul 23 |
peter |
\return An iterator to the first element in the range which does |
4349 |
19 Jul 23 |
peter |
not follow an ascending order - or \c last if the whole range is |
4349 |
19 Jul 23 |
peter |
sorted. |
4349 |
19 Jul 23 |
peter |
645 |
|
4349 |
19 Jul 23 |
peter |
\since New in yat 0.21 |
4349 |
19 Jul 23 |
peter |
647 |
*/ |
4349 |
19 Jul 23 |
peter |
648 |
template<typename InputIterator> |
4349 |
19 Jul 23 |
peter |
649 |
InputIterator is_sorted_until(InputIterator first, InputIterator last) |
4349 |
19 Jul 23 |
peter |
650 |
{ |
4349 |
19 Jul 23 |
peter |
651 |
typedef typename std::iterator_traits<InputIterator>::value_type Value; |
4349 |
19 Jul 23 |
peter |
652 |
BOOST_CONCEPT_ASSERT((boost::LessThanComparable<Value>)); |
4349 |
19 Jul 23 |
peter |
653 |
return utility::is_sorted_until(first, last, std::less<Value>()); |
4349 |
19 Jul 23 |
peter |
654 |
} |
4349 |
19 Jul 23 |
peter |
655 |
|
4349 |
19 Jul 23 |
peter |
656 |
/** |
1385 |
22 Jul 08 |
peter |
Creating a map from a range [first, last) such that m[key] |
1385 |
22 Jul 08 |
peter |
returns a vector with indices of which element in [first, last) |
1385 |
22 Jul 08 |
peter |
that is equal to \a key, or more technically: m[element].size() |
1385 |
22 Jul 08 |
peter |
returns number of elements equal to \a element, and |
1385 |
22 Jul 08 |
peter |
m[*element][i] = distance(first, element) for every \a element in |
1385 |
22 Jul 08 |
peter |
[first, last) and \a i smaller than m[element].size(). |
1385 |
22 Jul 08 |
peter |
663 |
|
1385 |
22 Jul 08 |
peter |
Requirement: InputIterator's value type is assignable to Key |
1385 |
22 Jul 08 |
peter |
665 |
|
1385 |
22 Jul 08 |
peter |
\since New in yat 0.5 |
1385 |
22 Jul 08 |
peter |
667 |
*/ |
2202 |
21 Feb 10 |
peter |
668 |
template<typename InputIterator, typename Key, typename Comp> |
1385 |
22 Jul 08 |
peter |
669 |
void inverse(InputIterator first, InputIterator last, |
2202 |
21 Feb 10 |
peter |
670 |
std::map<Key, std::vector<size_t>, Comp >& m) |
1385 |
22 Jul 08 |
peter |
671 |
{ |
2202 |
21 Feb 10 |
peter |
672 |
BOOST_CONCEPT_ASSERT((boost::InputIterator<InputIterator>)); |
2202 |
21 Feb 10 |
peter |
673 |
BOOST_CONCEPT_ASSERT((boost::Convertible<typename std::iterator_traits<InputIterator>::value_type, Key>)); |
1385 |
22 Jul 08 |
peter |
674 |
m.clear(); |
1385 |
22 Jul 08 |
peter |
675 |
for (size_t i=0; first!=last; ++i, ++first) |
1385 |
22 Jul 08 |
peter |
676 |
m[*first].push_back(i); |
1385 |
22 Jul 08 |
peter |
677 |
} |
1385 |
22 Jul 08 |
peter |
678 |
|
1385 |
22 Jul 08 |
peter |
679 |
/** |
1385 |
22 Jul 08 |
peter |
In the created multimap each element e will fulfill: \f$ *(first |
1385 |
22 Jul 08 |
peter |
+ e->second) == e->first \f$ |
1385 |
22 Jul 08 |
peter |
682 |
|
1385 |
22 Jul 08 |
peter |
Requirement: InputIterator's value type is assignable to Key |
1385 |
22 Jul 08 |
peter |
684 |
|
1385 |
22 Jul 08 |
peter |
\since New in yat 0.5 |
1385 |
22 Jul 08 |
peter |
686 |
*/ |
2202 |
21 Feb 10 |
peter |
687 |
template<typename Key, typename InputIterator, typename Comp> |
2730 |
24 Apr 12 |
peter |
688 |
void inverse(InputIterator first, InputIterator last, |
2202 |
21 Feb 10 |
peter |
689 |
std::multimap<Key, size_t, Comp>& m) |
1385 |
22 Jul 08 |
peter |
690 |
{ |
2202 |
21 Feb 10 |
peter |
691 |
BOOST_CONCEPT_ASSERT((boost::InputIterator<InputIterator>)); |
2202 |
21 Feb 10 |
peter |
692 |
BOOST_CONCEPT_ASSERT((boost::Convertible<typename std::iterator_traits<InputIterator>::value_type, Key>)); |
1385 |
22 Jul 08 |
peter |
693 |
m.clear(); |
1385 |
22 Jul 08 |
peter |
694 |
for (size_t i=0; first!=last; ++i, ++first) |
1385 |
22 Jul 08 |
peter |
695 |
m.insert(std::make_pair(*first, i)); |
1385 |
22 Jul 08 |
peter |
696 |
} |
1385 |
22 Jul 08 |
peter |
697 |
|
1385 |
22 Jul 08 |
peter |
698 |
|
1385 |
22 Jul 08 |
peter |
699 |
/** |
2857 |
27 Sep 12 |
peter |
Create a map mapping from values in range [first, last) to the |
2857 |
27 Sep 12 |
peter |
distance from first. |
2857 |
27 Sep 12 |
peter |
702 |
|
2857 |
27 Sep 12 |
peter |
Post-condition: m[first[i]] == i (for all i that correspond to a |
2857 |
27 Sep 12 |
peter |
unique element). For non-unique element behaviour is undefined. |
2857 |
27 Sep 12 |
peter |
705 |
|
2857 |
27 Sep 12 |
peter |
Requirement: InputIterator's value type is assignable to Key |
2857 |
27 Sep 12 |
peter |
707 |
|
2857 |
27 Sep 12 |
peter |
\since New in yat 0.10 |
2857 |
27 Sep 12 |
peter |
709 |
*/ |
2857 |
27 Sep 12 |
peter |
710 |
template<typename InputIterator, typename Key, typename Comp> |
2857 |
27 Sep 12 |
peter |
711 |
void inverse(InputIterator first, InputIterator last, |
2857 |
27 Sep 12 |
peter |
712 |
std::map<Key, size_t, Comp >& m) |
2857 |
27 Sep 12 |
peter |
713 |
{ |
2857 |
27 Sep 12 |
peter |
714 |
BOOST_CONCEPT_ASSERT((boost::InputIterator<InputIterator>)); |
2857 |
27 Sep 12 |
peter |
715 |
BOOST_CONCEPT_ASSERT((boost::Convertible<typename std::iterator_traits<InputIterator>::value_type, Key>)); |
2857 |
27 Sep 12 |
peter |
716 |
m.clear(); |
2857 |
27 Sep 12 |
peter |
717 |
for (size_t i=0; first!=last; ++i, ++first) |
2857 |
27 Sep 12 |
peter |
718 |
m[*first] = i; |
2857 |
27 Sep 12 |
peter |
719 |
} |
2857 |
27 Sep 12 |
peter |
720 |
|
2857 |
27 Sep 12 |
peter |
721 |
/** |
1966 |
08 May 09 |
peter |
\brief Functor that behaves like std::less with the exception |
3286 |
11 Jul 14 |
peter |
that it treats NaN as a number larger than infinity. |
1966 |
08 May 09 |
peter |
724 |
|
1966 |
08 May 09 |
peter |
This functor is useful when sorting ranges with NaNs. The problem |
1966 |
08 May 09 |
peter |
with NaNs is that std::less always returns \c false when one of |
1966 |
08 May 09 |
peter |
the arguments is NaN. That together with the fact that std::sort |
1966 |
08 May 09 |
peter |
only guarantees that an element \c i is never less than previous |
1966 |
08 May 09 |
peter |
element \c --i. Therefore {10, NaN, 2} is sorted according to |
1966 |
08 May 09 |
peter |
this definition, but most often it is desired that the 2 is |
1966 |
08 May 09 |
peter |
located before the 10 in the range. Using this functor, less_nan, |
1966 |
08 May 09 |
peter |
this can easily be achieved as std::sort(first, last, less_nan) |
1966 |
08 May 09 |
peter |
733 |
|
1970 |
11 May 09 |
peter |
The default implementation uses std::isnan(T), which consequently |
1970 |
11 May 09 |
peter |
must be supported. |
1966 |
08 May 09 |
peter |
736 |
|
1970 |
11 May 09 |
peter |
There is a specialization less_nan<DataWeight> |
1970 |
11 May 09 |
peter |
738 |
|
1966 |
08 May 09 |
peter |
\since New in yat 0.6 |
1966 |
08 May 09 |
peter |
740 |
*/ |
1966 |
08 May 09 |
peter |
741 |
template<typename T> |
4339 |
15 Apr 23 |
peter |
742 |
struct less_nan |
1966 |
08 May 09 |
peter |
743 |
{ |
4339 |
15 Apr 23 |
peter |
/// \c first_argument_type is \c T |
4339 |
15 Apr 23 |
peter |
745 |
typedef T first_argument_type; |
4339 |
15 Apr 23 |
peter |
/// \c second_argument_type is \c T |
4339 |
15 Apr 23 |
peter |
747 |
typedef T second_argument_type; |
4339 |
15 Apr 23 |
peter |
/// \c result_type is \c bool |
4339 |
15 Apr 23 |
peter |
749 |
typedef bool result_type; |
4339 |
15 Apr 23 |
peter |
750 |
|
1966 |
08 May 09 |
peter |
751 |
/** |
1966 |
08 May 09 |
peter |
\return \c true if x is less than y. NaNs are treated as a number |
1966 |
08 May 09 |
peter |
larger than infinity, which implies \c true is returned if y is |
1966 |
08 May 09 |
peter |
NaN and x is not. |
1966 |
08 May 09 |
peter |
755 |
*/ |
1966 |
08 May 09 |
peter |
756 |
inline bool operator()(T x, T y) const |
2730 |
24 Apr 12 |
peter |
757 |
{ |
1966 |
08 May 09 |
peter |
758 |
if (std::isnan(x)) |
1966 |
08 May 09 |
peter |
759 |
return false; |
1966 |
08 May 09 |
peter |
760 |
if (std::isnan(y)) |
1966 |
08 May 09 |
peter |
761 |
return true; |
1966 |
08 May 09 |
peter |
762 |
return x<y; |
1966 |
08 May 09 |
peter |
763 |
} |
1966 |
08 May 09 |
peter |
764 |
}; |
1966 |
08 May 09 |
peter |
765 |
|
1966 |
08 May 09 |
peter |
766 |
|
1966 |
08 May 09 |
peter |
767 |
/** |
1970 |
11 May 09 |
peter |
\brief Specialization for DataWeight. |
1970 |
11 May 09 |
peter |
769 |
*/ |
1970 |
11 May 09 |
peter |
770 |
template<> |
2730 |
24 Apr 12 |
peter |
771 |
struct less_nan<DataWeight> |
1970 |
11 May 09 |
peter |
772 |
{ |
4339 |
15 Apr 23 |
peter |
/// \c first_argument_type is \c DataWeight |
4339 |
15 Apr 23 |
peter |
774 |
typedef DataWeight first_argument_type; |
4339 |
15 Apr 23 |
peter |
/// \c second_argument_type is \c DataWeight |
4339 |
15 Apr 23 |
peter |
776 |
typedef DataWeight second_argument_type; |
4339 |
15 Apr 23 |
peter |
/// \c result_type is \c bool |
4339 |
15 Apr 23 |
peter |
778 |
typedef bool result_type; |
4339 |
15 Apr 23 |
peter |
779 |
|
1970 |
11 May 09 |
peter |
780 |
/** |
1970 |
11 May 09 |
peter |
\return less_nan<double>(x.data(), y.data()) |
1970 |
11 May 09 |
peter |
782 |
*/ |
1970 |
11 May 09 |
peter |
783 |
inline bool operator()(const DataWeight& x, const DataWeight& y) const |
2730 |
24 Apr 12 |
peter |
784 |
{ |
1970 |
11 May 09 |
peter |
785 |
less_nan<double> compare; |
1970 |
11 May 09 |
peter |
786 |
return compare(x.data(), y.data()); |
1970 |
11 May 09 |
peter |
787 |
} |
1970 |
11 May 09 |
peter |
788 |
}; |
1970 |
11 May 09 |
peter |
789 |
|
1970 |
11 May 09 |
peter |
790 |
|
1970 |
11 May 09 |
peter |
791 |
/** |
1288 |
24 Apr 08 |
peter |
Functor class to take logarithm |
1339 |
06 Jun 08 |
peter |
793 |
|
1998 |
13 Jun 09 |
peter |
T should be either \c float, \c double, or \c long \c double |
1998 |
13 Jun 09 |
peter |
795 |
|
1339 |
06 Jun 08 |
peter |
\since New in yat 0.5 |
1288 |
24 Apr 08 |
peter |
797 |
*/ |
1288 |
24 Apr 08 |
peter |
798 |
template<typename T> |
4339 |
15 Apr 23 |
peter |
799 |
class Log |
1288 |
24 Apr 08 |
peter |
800 |
{ |
1288 |
24 Apr 08 |
peter |
801 |
public: |
4339 |
15 Apr 23 |
peter |
/// \c argument_type is \c T |
4339 |
15 Apr 23 |
peter |
803 |
typedef T argument_type; |
4339 |
15 Apr 23 |
peter |
/// \c result_type is \c T |
4339 |
15 Apr 23 |
peter |
805 |
typedef T result_type; |
4339 |
15 Apr 23 |
peter |
806 |
|
1288 |
24 Apr 08 |
peter |
807 |
/** |
1288 |
24 Apr 08 |
peter |
Default constructor using natural base \f$ e \f$ |
1288 |
24 Apr 08 |
peter |
809 |
*/ |
1288 |
24 Apr 08 |
peter |
810 |
Log(void) |
1288 |
24 Apr 08 |
peter |
811 |
: log_base_(1.0) {} |
1288 |
24 Apr 08 |
peter |
812 |
|
1288 |
24 Apr 08 |
peter |
813 |
/** |
1288 |
24 Apr 08 |
peter |
\param base Taking logarithm in which base, e.g. 2 or 10. |
1288 |
24 Apr 08 |
peter |
815 |
*/ |
1288 |
24 Apr 08 |
peter |
816 |
explicit Log(double base) : log_base_(std::log(base)) {} |
1288 |
24 Apr 08 |
peter |
817 |
|
1288 |
24 Apr 08 |
peter |
818 |
/** |
1341 |
17 Jun 08 |
peter |
\return logarithm |
1288 |
24 Apr 08 |
peter |
820 |
*/ |
1288 |
24 Apr 08 |
peter |
821 |
inline T operator()(T x) const |
1288 |
24 Apr 08 |
peter |
822 |
{ return std::log(x)/log_base_; } |
1288 |
24 Apr 08 |
peter |
823 |
|
1288 |
24 Apr 08 |
peter |
824 |
private: |
1288 |
24 Apr 08 |
peter |
825 |
double log_base_; |
1288 |
24 Apr 08 |
peter |
826 |
}; |
1288 |
24 Apr 08 |
peter |
827 |
|
1288 |
24 Apr 08 |
peter |
828 |
/** |
869 |
14 Sep 07 |
peter |
\return max of values |
869 |
14 Sep 07 |
peter |
830 |
*/ |
869 |
14 Sep 07 |
peter |
831 |
template <typename T> |
869 |
14 Sep 07 |
peter |
832 |
T max(const T& a, const T& b, const T& c) |
869 |
14 Sep 07 |
peter |
833 |
{ |
869 |
14 Sep 07 |
peter |
834 |
return std::max(std::max(a,b),c); |
869 |
14 Sep 07 |
peter |
835 |
} |
432 |
13 Dec 05 |
markus |
836 |
|
869 |
14 Sep 07 |
peter |
837 |
|
869 |
14 Sep 07 |
peter |
838 |
/** |
869 |
14 Sep 07 |
peter |
\return max of values |
869 |
14 Sep 07 |
peter |
840 |
*/ |
869 |
14 Sep 07 |
peter |
841 |
template <typename T> |
869 |
14 Sep 07 |
peter |
842 |
T max(const T& a, const T& b, const T& c, const T& d) |
869 |
14 Sep 07 |
peter |
843 |
{ |
869 |
14 Sep 07 |
peter |
844 |
return std::max(std::max(a,b), std::max(c,d)); |
869 |
14 Sep 07 |
peter |
845 |
} |
869 |
14 Sep 07 |
peter |
846 |
|
869 |
14 Sep 07 |
peter |
847 |
|
869 |
14 Sep 07 |
peter |
848 |
/** |
869 |
14 Sep 07 |
peter |
\return max of values |
869 |
14 Sep 07 |
peter |
850 |
*/ |
869 |
14 Sep 07 |
peter |
851 |
template <typename T> |
869 |
14 Sep 07 |
peter |
852 |
T max(const T& a, const T& b, const T& c, const T& d, const T& e) |
869 |
14 Sep 07 |
peter |
853 |
{ |
869 |
14 Sep 07 |
peter |
854 |
return std::max(max(a,b,c,d), e); |
869 |
14 Sep 07 |
peter |
855 |
} |
869 |
14 Sep 07 |
peter |
856 |
|
869 |
14 Sep 07 |
peter |
857 |
|
869 |
14 Sep 07 |
peter |
858 |
/** |
869 |
14 Sep 07 |
peter |
\return max of values |
869 |
14 Sep 07 |
peter |
860 |
*/ |
869 |
14 Sep 07 |
peter |
861 |
template <typename T> |
869 |
14 Sep 07 |
peter |
862 |
T max(const T& a, const T& b, const T& c, const T& d, const T& e, const T& f) |
869 |
14 Sep 07 |
peter |
863 |
{ |
869 |
14 Sep 07 |
peter |
864 |
return std::max(max(a,b,c,d), std::max(e,f)); |
869 |
14 Sep 07 |
peter |
865 |
} |
869 |
14 Sep 07 |
peter |
866 |
|
869 |
14 Sep 07 |
peter |
867 |
|
58 |
14 Apr 04 |
jari |
868 |
/// |
767 |
22 Feb 07 |
peter |
/// @brief Functor comparing pairs using second. |
767 |
22 Feb 07 |
peter |
870 |
/// |
58 |
14 Apr 04 |
jari |
/// STL provides operator< for the pair.first element, but none for |
58 |
14 Apr 04 |
jari |
/// pair.second. This template provides this and can be used as the |
58 |
14 Apr 04 |
jari |
/// comparison object in generic functions such as the STL sort. |
58 |
14 Apr 04 |
jari |
874 |
/// |
58 |
14 Apr 04 |
jari |
875 |
template <class T1,class T2> |
58 |
14 Apr 04 |
jari |
876 |
struct pair_value_compare |
58 |
14 Apr 04 |
jari |
877 |
{ |
295 |
29 Apr 05 |
peter |
878 |
/// |
1844 |
02 Mar 09 |
peter |
/// @return true if x.second<y.second or (!(y.second<y.second) and |
295 |
29 Apr 05 |
peter |
/// x.first<y.first) |
295 |
29 Apr 05 |
peter |
881 |
/// |
58 |
14 Apr 04 |
jari |
882 |
inline bool operator()(const std::pair<T1,T2>& x, |
58 |
14 Apr 04 |
jari |
883 |
const std::pair<T1,T2>& y) { |
58 |
14 Apr 04 |
jari |
884 |
return ((x.second<y.second) || |
2730 |
24 Apr 12 |
peter |
885 |
(!(y.second<x.second) && (x.first<y.first))); |
58 |
14 Apr 04 |
jari |
886 |
} |
58 |
14 Apr 04 |
jari |
887 |
}; |
58 |
14 Apr 04 |
jari |
888 |
|
1399 |
06 Aug 08 |
peter |
889 |
/** |
1399 |
06 Aug 08 |
peter |
\brief Functor that return std::pair.first |
1399 |
06 Aug 08 |
peter |
891 |
|
1399 |
06 Aug 08 |
peter |
\see pair_first_iterator |
1399 |
06 Aug 08 |
peter |
893 |
|
1399 |
06 Aug 08 |
peter |
\since New in yat 0.5 |
1399 |
06 Aug 08 |
peter |
895 |
*/ |
1399 |
06 Aug 08 |
peter |
896 |
template <class Pair> |
2730 |
24 Apr 12 |
peter |
897 |
struct PairFirst |
1399 |
06 Aug 08 |
peter |
898 |
{ |
1399 |
06 Aug 08 |
peter |
899 |
/** |
1399 |
06 Aug 08 |
peter |
The type returned is Pair::first_type& with the exception when |
1399 |
06 Aug 08 |
peter |
Pair is const and Pair::first_type is non-const, in which case |
1399 |
06 Aug 08 |
peter |
const Pair::first_type& is return type. |
1399 |
06 Aug 08 |
peter |
903 |
*/ |
1399 |
06 Aug 08 |
peter |
904 |
typedef typename boost::mpl::if_< |
2730 |
24 Apr 12 |
peter |
905 |
typename boost::is_const<Pair>::type, |
1399 |
06 Aug 08 |
peter |
906 |
typename boost::add_const<typename Pair::first_type>::type&, |
1399 |
06 Aug 08 |
peter |
907 |
typename Pair::first_type&>::type result_type; |
2730 |
24 Apr 12 |
peter |
908 |
|
1399 |
06 Aug 08 |
peter |
909 |
/** |
1399 |
06 Aug 08 |
peter |
The argument type is Pair&. |
1399 |
06 Aug 08 |
peter |
911 |
*/ |
1399 |
06 Aug 08 |
peter |
912 |
typedef Pair& argument_type; |
1399 |
06 Aug 08 |
peter |
913 |
|
1399 |
06 Aug 08 |
peter |
914 |
/** |
1399 |
06 Aug 08 |
peter |
\return p.first |
1399 |
06 Aug 08 |
peter |
916 |
*/ |
1399 |
06 Aug 08 |
peter |
917 |
inline result_type operator()(argument_type p) const |
1399 |
06 Aug 08 |
peter |
918 |
{ return p.first; } |
1399 |
06 Aug 08 |
peter |
919 |
|
1399 |
06 Aug 08 |
peter |
920 |
}; |
1399 |
06 Aug 08 |
peter |
921 |
|
1399 |
06 Aug 08 |
peter |
922 |
|
1399 |
06 Aug 08 |
peter |
923 |
/** |
1403 |
07 Aug 08 |
peter |
\brief Functor that return std::pair.second |
1403 |
07 Aug 08 |
peter |
925 |
|
1403 |
07 Aug 08 |
peter |
\see pair_second_iterator |
1403 |
07 Aug 08 |
peter |
927 |
|
1403 |
07 Aug 08 |
peter |
\since New in yat 0.5 |
1403 |
07 Aug 08 |
peter |
929 |
*/ |
1403 |
07 Aug 08 |
peter |
930 |
template <class Pair> |
2730 |
24 Apr 12 |
peter |
931 |
struct PairSecond |
1403 |
07 Aug 08 |
peter |
932 |
{ |
1403 |
07 Aug 08 |
peter |
933 |
/** |
1403 |
07 Aug 08 |
peter |
The type returned is Pair::second_type& with the exception when |
1403 |
07 Aug 08 |
peter |
Pair is const and Pair::second_type is non-const, in which case |
1403 |
07 Aug 08 |
peter |
const Pair::first_type& is return type. |
1403 |
07 Aug 08 |
peter |
937 |
*/ |
1403 |
07 Aug 08 |
peter |
938 |
typedef typename boost::mpl::if_< |
2730 |
24 Apr 12 |
peter |
939 |
typename boost::is_const<Pair>::type, |
1403 |
07 Aug 08 |
peter |
940 |
typename boost::add_const<typename Pair::second_type>::type&, |
1403 |
07 Aug 08 |
peter |
941 |
typename Pair::second_type&>::type result_type; |
2730 |
24 Apr 12 |
peter |
942 |
|
1403 |
07 Aug 08 |
peter |
943 |
/** |
1403 |
07 Aug 08 |
peter |
The argument type is Pair&. |
1403 |
07 Aug 08 |
peter |
945 |
*/ |
1403 |
07 Aug 08 |
peter |
946 |
typedef Pair& argument_type; |
1403 |
07 Aug 08 |
peter |
947 |
|
1403 |
07 Aug 08 |
peter |
948 |
/** |
1403 |
07 Aug 08 |
peter |
\return p.first |
1403 |
07 Aug 08 |
peter |
950 |
*/ |
1403 |
07 Aug 08 |
peter |
951 |
inline result_type operator()(argument_type p) const |
1403 |
07 Aug 08 |
peter |
952 |
{ return p.second; } |
1403 |
07 Aug 08 |
peter |
953 |
|
1403 |
07 Aug 08 |
peter |
954 |
}; |
1403 |
07 Aug 08 |
peter |
955 |
|
1403 |
07 Aug 08 |
peter |
956 |
|
1403 |
07 Aug 08 |
peter |
957 |
/** |
1399 |
06 Aug 08 |
peter |
Creates a transform_iterator that transforms an iterator with |
1399 |
06 Aug 08 |
peter |
value type std::pair to an iterator with value type |
1399 |
06 Aug 08 |
peter |
std::pair::first_type. This can be used, for example, to |
1399 |
06 Aug 08 |
peter |
communicate between a std::map and std::vector |
1399 |
06 Aug 08 |
peter |
962 |
|
1399 |
06 Aug 08 |
peter |
\code |
1399 |
06 Aug 08 |
peter |
std::map<std::string, int> map; |
1399 |
06 Aug 08 |
peter |
965 |
... |
1399 |
06 Aug 08 |
peter |
std::vector<std::string> vec; |
1399 |
06 Aug 08 |
peter |
vec.resize(map.size()); |
1399 |
06 Aug 08 |
peter |
std::copy(pair_first_iterator(map.begin()), pair_first_iterator(map.end()), |
1399 |
06 Aug 08 |
peter |
vec.begin()); |
1399 |
06 Aug 08 |
peter |
\endcode |
1399 |
06 Aug 08 |
peter |
971 |
|
1399 |
06 Aug 08 |
peter |
\since New in yat 0.5 |
1399 |
06 Aug 08 |
peter |
973 |
*/ |
1399 |
06 Aug 08 |
peter |
974 |
template<class Iter> |
1399 |
06 Aug 08 |
peter |
975 |
boost::transform_iterator< |
2068 |
17 Sep 09 |
peter |
976 |
PairFirst<typename boost::remove_reference< |
2068 |
17 Sep 09 |
peter |
977 |
typename std::iterator_traits<Iter>::reference |
2068 |
17 Sep 09 |
peter |
978 |
>::type>, |
1399 |
06 Aug 08 |
peter |
979 |
Iter> pair_first_iterator(Iter i) |
1399 |
06 Aug 08 |
peter |
980 |
{ |
2068 |
17 Sep 09 |
peter |
// We are going via ::reference in order to remain const info; |
2068 |
17 Sep 09 |
peter |
// ::value_type does not contain const information. |
2068 |
17 Sep 09 |
peter |
983 |
typedef typename std::iterator_traits<Iter>::reference ref_type; |
2068 |
17 Sep 09 |
peter |
984 |
typedef typename boost::remove_reference<ref_type>::type val_type; |
2730 |
24 Apr 12 |
peter |
985 |
typedef PairFirst<val_type> PF; |
1399 |
06 Aug 08 |
peter |
986 |
return boost::transform_iterator<PF, Iter>(i, PF()); |
1399 |
06 Aug 08 |
peter |
987 |
} |
1399 |
06 Aug 08 |
peter |
988 |
|
1399 |
06 Aug 08 |
peter |
989 |
|
1403 |
07 Aug 08 |
peter |
990 |
/** |
1403 |
07 Aug 08 |
peter |
Creates a transform_iterator that transforms an iterator with |
1403 |
07 Aug 08 |
peter |
value type std::pair to an iterator with value type |
1403 |
07 Aug 08 |
peter |
std::pair::second_type. This can be used, for example, to |
1403 |
07 Aug 08 |
peter |
communicate between a std::map and std::vector |
1399 |
06 Aug 08 |
peter |
995 |
|
1403 |
07 Aug 08 |
peter |
\code |
1403 |
07 Aug 08 |
peter |
std::map<std::string, int> map; |
1403 |
07 Aug 08 |
peter |
998 |
... |
1403 |
07 Aug 08 |
peter |
std::vector<int> vec(map.size(),0); |
1403 |
07 Aug 08 |
peter |
std::copy(vec.begin(), vec.end(), pair_second_iterator(map.begin())); |
1403 |
07 Aug 08 |
peter |
\endcode |
1399 |
06 Aug 08 |
peter |
1002 |
|
1403 |
07 Aug 08 |
peter |
\since New in yat 0.5 |
1403 |
07 Aug 08 |
peter |
1004 |
*/ |
1403 |
07 Aug 08 |
peter |
1005 |
template<class Iter> |
1403 |
07 Aug 08 |
peter |
1006 |
boost::transform_iterator< |
2068 |
17 Sep 09 |
peter |
1007 |
PairSecond<typename boost::remove_reference< |
2068 |
17 Sep 09 |
peter |
1008 |
typename std::iterator_traits<Iter>::reference |
2068 |
17 Sep 09 |
peter |
1009 |
>::type>, |
1403 |
07 Aug 08 |
peter |
1010 |
Iter> pair_second_iterator(Iter i) |
1403 |
07 Aug 08 |
peter |
1011 |
{ |
2068 |
17 Sep 09 |
peter |
// We are going via ::reference in order to remain const info; |
2068 |
17 Sep 09 |
peter |
// ::value_type does not contain const information. |
2068 |
17 Sep 09 |
peter |
1014 |
typedef typename std::iterator_traits<Iter>::reference ref_type; |
2068 |
17 Sep 09 |
peter |
1015 |
typedef typename boost::remove_reference<ref_type>::type val_type; |
2730 |
24 Apr 12 |
peter |
1016 |
typedef PairSecond<val_type> PS; |
2068 |
17 Sep 09 |
peter |
1017 |
return boost::transform_iterator<PS, Iter>(i, PS()); |
1403 |
07 Aug 08 |
peter |
1018 |
} |
1403 |
07 Aug 08 |
peter |
1019 |
|
1403 |
07 Aug 08 |
peter |
1020 |
|
2239 |
10 Apr 10 |
peter |
1021 |
/** |
2286 |
27 Jun 10 |
peter |
Convenient function that creates a binary predicate that can be |
2286 |
27 Jun 10 |
peter |
used to compare pointers when you want to compare them with |
2286 |
27 Jun 10 |
peter |
respect to the objects they point to. |
1403 |
07 Aug 08 |
peter |
1025 |
|
2239 |
10 Apr 10 |
peter |
Example: |
2239 |
10 Apr 10 |
peter |
\code |
2239 |
10 Apr 10 |
peter |
std::vector<MyClass*> vec(18); |
2239 |
10 Apr 10 |
peter |
1029 |
... |
2730 |
24 Apr 12 |
peter |
std::sort(vec.begin(), vec.end(), |
3247 |
04 Jun 14 |
peter |
make_ptr_compare(vec[0], std::greater<MyClass>())); |
2239 |
10 Apr 10 |
peter |
\endcode |
1403 |
07 Aug 08 |
peter |
1033 |
|
2239 |
10 Apr 10 |
peter |
1034 |
|
2286 |
27 Jun 10 |
peter |
Type Requirement: |
2286 |
27 Jun 10 |
peter |
- \a compare must be a <a |
2286 |
27 Jun 10 |
peter |
href="http://www.sgi.com/tech/stl/AdaptableBinaryPredicate.html">Adaptable |
2286 |
27 Jun 10 |
peter |
Binary Predicate</a>. |
2286 |
27 Jun 10 |
peter |
- value_type of Pointer must be convertible to argument_type of |
2286 |
27 Jun 10 |
peter |
compare |
2286 |
27 Jun 10 |
peter |
1041 |
|
2286 |
27 Jun 10 |
peter |
\return a compose_f_gx_hy in which \c F is defined by \a compare |
2286 |
27 Jun 10 |
peter |
and both \c G and \c H are \c Dereferencer functors. |
2286 |
27 Jun 10 |
peter |
1044 |
|
2286 |
27 Jun 10 |
peter |
\see compose_f_gx_hy |
2286 |
27 Jun 10 |
peter |
1046 |
|
2239 |
10 Apr 10 |
peter |
\since New in yat 0.7 |
2239 |
10 Apr 10 |
peter |
1048 |
*/ |
2286 |
27 Jun 10 |
peter |
1049 |
template<typename Pointer, class Compare> |
2286 |
27 Jun 10 |
peter |
1050 |
compose_f_gx_hy<Compare, Dereferencer<Pointer>, Dereferencer<Pointer> > |
2286 |
27 Jun 10 |
peter |
1051 |
make_ptr_compare(Pointer p, Compare compare) |
2239 |
10 Apr 10 |
peter |
1052 |
{ |
2286 |
27 Jun 10 |
peter |
1053 |
return make_compose_f_gx_hy(compare, Dereferencer<Pointer>(), |
2286 |
27 Jun 10 |
peter |
1054 |
Dereferencer<Pointer>()); |
2286 |
27 Jun 10 |
peter |
1055 |
} |
2239 |
10 Apr 10 |
peter |
1056 |
|
2286 |
27 Jun 10 |
peter |
1057 |
/** |
2286 |
27 Jun 10 |
peter |
Same as make_ptr_compare(2) except that std::less is used to |
2286 |
27 Jun 10 |
peter |
compare pointers. |
2239 |
10 Apr 10 |
peter |
1060 |
|
2286 |
27 Jun 10 |
peter |
\since New in yat 0.7 |
2286 |
27 Jun 10 |
peter |
1062 |
*/ |
2286 |
27 Jun 10 |
peter |
1063 |
template<typename Pointer> |
2286 |
27 Jun 10 |
peter |
1064 |
compose_f_gx_hy<std::less<typename std::iterator_traits<Pointer>::value_type>, |
2286 |
27 Jun 10 |
peter |
1065 |
Dereferencer<Pointer>, Dereferencer<Pointer> > |
2286 |
27 Jun 10 |
peter |
1066 |
make_ptr_compare(Pointer p) |
2286 |
27 Jun 10 |
peter |
1067 |
{ |
2286 |
27 Jun 10 |
peter |
1068 |
typedef typename std::iterator_traits<Pointer>::value_type value_type; |
2286 |
27 Jun 10 |
peter |
1069 |
BOOST_CONCEPT_ASSERT((boost::LessThanComparable<value_type>)); |
2286 |
27 Jun 10 |
peter |
1070 |
std::less<value_type> compare; |
2286 |
27 Jun 10 |
peter |
1071 |
return make_ptr_compare(p, compare); |
2286 |
27 Jun 10 |
peter |
1072 |
} |
2239 |
10 Apr 10 |
peter |
1073 |
|
2239 |
10 Apr 10 |
peter |
1074 |
|
262 |
07 Apr 05 |
peter |
1075 |
/// |
703 |
18 Dec 06 |
jari |
/// @brief Function converting a string to lower case |
436 |
14 Dec 05 |
markus |
1077 |
/// |
919 |
30 Sep 07 |
peter |
1078 |
std::string& to_lower(std::string& s); |
262 |
07 Apr 05 |
peter |
1079 |
|
436 |
14 Dec 05 |
markus |
1080 |
/// |
703 |
18 Dec 06 |
jari |
/// @brief Function converting a string to upper case |
436 |
14 Dec 05 |
markus |
1082 |
/// |
919 |
30 Sep 07 |
peter |
1083 |
std::string& to_upper(std::string& s); |
436 |
14 Dec 05 |
markus |
1084 |
|
2181 |
02 Feb 10 |
peter |
1085 |
|
2181 |
02 Feb 10 |
peter |
// template implementations |
2181 |
02 Feb 10 |
peter |
1087 |
|
3254 |
09 Jun 14 |
peter |
1088 |
template <typename Key, typename Tp, typename Compare, typename Alloc, |
3254 |
09 Jun 14 |
peter |
1089 |
typename Key2> |
3254 |
09 Jun 14 |
peter |
1090 |
const Tp& get(const std::map<Key, Tp, Compare, Alloc>& m, const Key2& key) |
2181 |
02 Feb 10 |
peter |
1091 |
{ |
3254 |
09 Jun 14 |
peter |
1092 |
BOOST_CONCEPT_ASSERT((boost::Convertible<Key2, Key>)); |
2530 |
28 Jul 11 |
peter |
1093 |
typename std::map<Key, Tp, Compare,Alloc>::const_iterator iter(m.find(key)); |
2181 |
02 Feb 10 |
peter |
1094 |
if (iter==m.end()) { |
3254 |
09 Jun 14 |
peter |
// Avoid throw exception with Key2 because we do not want to |
3254 |
09 Jun 14 |
peter |
// require that Key2 is copy constructible. We know that Key is |
3254 |
09 Jun 14 |
peter |
// copy constructible from std::map requirement. |
3253 |
07 Jun 14 |
peter |
1098 |
throw |
3253 |
07 Jun 14 |
peter |
1099 |
get_error<Key>("utility::get(const Map&, const Key&): key not found", |
3253 |
07 Jun 14 |
peter |
1100 |
key); |
2181 |
02 Feb 10 |
peter |
1101 |
} |
2181 |
02 Feb 10 |
peter |
1102 |
return iter->second; |
2181 |
02 Feb 10 |
peter |
1103 |
} |
2181 |
02 Feb 10 |
peter |
1104 |
|
687 |
16 Oct 06 |
jari |
1105 |
}}} // of namespace utility, yat, and theplu |
58 |
14 Apr 04 |
jari |
1106 |
#endif |