blob: 9bc3c773d368ea3c57cc191705c50ffc8c37d66b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
// Copyright (C) 2003 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_SEQUENCE_COMPARe_1_
#define DLIB_SEQUENCE_COMPARe_1_
#include "sequence_compare_abstract.h"
#include "../algs.h"
namespace dlib
{
template <
typename seq_base
>
class sequence_compare_1 : public seq_base
{
typedef typename seq_base::type T;
public:
bool operator< (
const sequence_compare_1& rhs
) const;
bool operator== (
const sequence_compare_1& rhs
) const;
};
template <
typename seq_base
>
inline void swap (
sequence_compare_1<seq_base>& a,
sequence_compare_1<seq_base>& b
) { a.swap(b); }
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// member function definitions
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template <
typename seq_base
>
bool sequence_compare_1<seq_base>::
operator< (
const sequence_compare_1<seq_base>& rhs
) const
{
unsigned int length;
if (this->size() < rhs.size())
length = this->size();
else
length = rhs.size();
for (unsigned long i = 0; i < length; ++i)
{
if ((*this)[i] < rhs[i])
return true;
else if ( !((*this)[i] == rhs[i]) )
return false;
}
// they are equal so far
if (this->size() < rhs.size())
return true;
else
return false;
}
// ----------------------------------------------------------------------------------------
template <
typename seq_base
>
bool sequence_compare_1<seq_base>::
operator== (
const sequence_compare_1<seq_base>& rhs
) const
{
if (this->size() != rhs.size())
return false;
for (unsigned long i = 0; i < this->size(); ++i)
{
if (!((*this)[i] == rhs[i]))
return false;
}
return true;
}
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_SEQUENCE_COMPARe_1_
|