~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to extra/yassl/taocrypt/mySTL/algorithm.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
   Copyright (C) 2000-2007 MySQL AB
 
3
 
 
4
   This program is free software; you can redistribute it and/or modify
 
5
   it under the terms of the GNU General Public License as published by
 
6
   the Free Software Foundation; version 2 of the License.
 
7
 
 
8
   This program is distributed in the hope that it will be useful,
 
9
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
   GNU General Public License for more details.
 
12
 
 
13
   You should have received a copy of the GNU General Public License
 
14
   along with this program; see the file COPYING. If not, write to the
 
15
   Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
 
16
   MA  02110-1301  USA.
 
17
*/
 
18
 
 
19
 
 
20
/* mySTL algorithm implements max, min, for_each, swap, find_if, copy,
 
21
 * copy_backward, fill
 
22
 */
 
23
 
 
24
#ifndef mySTL_ALGORITHM_HPP
 
25
#define mySTL_ALGORITHM_HPP
 
26
 
 
27
 
 
28
namespace mySTL {
 
29
 
 
30
 
 
31
template<typename T>
 
32
inline const T& max(const T& a, const T&b)
 
33
{
 
34
    return a < b ? b : a;
 
35
}
 
36
 
 
37
 
 
38
template<typename T>
 
39
inline const T& min(const T& a, const T&b)
 
40
{
 
41
    return b < a ? b : a;
 
42
}
 
43
 
 
44
 
 
45
template<typename InIter, typename Func>
 
46
Func for_each(InIter first, InIter last, Func op)
 
47
{
 
48
    while (first != last) {
 
49
        op(*first);
 
50
        ++first;
 
51
    }
 
52
    return op;
 
53
}
 
54
 
 
55
 
 
56
template<typename T>
 
57
inline void swap(T& a, T& b)
 
58
{
 
59
    T tmp = a;
 
60
    a = b;
 
61
    b = tmp;
 
62
}
 
63
 
 
64
 
 
65
template<typename InIter, typename Pred>
 
66
InIter find_if(InIter first, InIter last, Pred pred)
 
67
{
 
68
    while (first != last && !pred(*first))
 
69
        ++first;
 
70
    return first;
 
71
}
 
72
 
 
73
 
 
74
template<typename InputIter, typename OutputIter>
 
75
inline OutputIter copy(InputIter first, InputIter last, OutputIter place)
 
76
{
 
77
    while (first != last) {
 
78
        *place = *first;
 
79
        ++first;
 
80
        ++place;
 
81
    }
 
82
    return place;
 
83
}
 
84
 
 
85
 
 
86
template<typename InputIter, typename OutputIter>
 
87
inline OutputIter 
 
88
copy_backward(InputIter first, InputIter last, OutputIter place)
 
89
{
 
90
    while (first != last)
 
91
        *--place = *--last;
 
92
    return place;
 
93
}
 
94
 
 
95
 
 
96
template<typename InputIter, typename T>
 
97
void fill(InputIter first, InputIter last, const T& v)
 
98
{
 
99
    while (first != last) {
 
100
        *first = v;
 
101
        ++first;
 
102
    }
 
103
}
 
104
 
 
105
 
 
106
}  // namespace mySTL
 
107
 
 
108
#endif // mySTL_ALGORITHM_HPP