Problem with std::lexicographical_compare

I am trying to implement mVector<T>'s relational operators. The link is here :
http://www.cplusplus.com/reference/vector/vector/operators/

This is what I have :
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
static bool _comp_greater_equal(T t1, T t2) {return t1 >= t2;}
static bool _comp_greater(T t1, T t2) {return t1 > t2;}
static bool _comp_equal(T t1, T t2) {return t1 == t2;}
static bool _comp_lower(T t1, T t2) {return t1 < t2;}
static bool _comp_lower_equal(T t1, T t2) {return t1 <= t2;}
static bool _comp_not_equal(T t1, T t2) {return t1 != t2;}

inline bool operator >= (const mVector<T> &v) const 
{
	return (this->size() > v.size() || this->size() == v.size()  && std::lexicographical_compare(this->begin().t, this->end().t, v.begin().t, v.end().t, _comp_greater_equal));
}
inline bool operator > (const mVector<T> &v) const 
{
	return (this->size() > v.size() || std::lexicographical_compare(this->begin().t, this->end().t, v.begin().t, v.end().t, _comp_greater));
}
inline bool operator == (const mVector<T> &v) const 
{
	return (this->size() == v.size() && std::lexicographical_compare(this->begin().t, this->end().t, v.begin().t, v.end().t, _comp_equal));
}
inline bool operator < (const mVector<T> &v) const 
{
	return (this->size() < v.size() || std::lexicographical_compare(this->begin().t, this->end().t, v.begin().t, v.end().t, _comp_lower));
}
inline bool operator <= (const mVector<T> &v) const 
{
	return (this->size() < v.size() || this->size() == v.size() && std::lexicographical_compare(this->begin().t, this->end().t, v.begin().t, v.end().t, _comp_lower_equal));
}
inline bool operator != (const mVector<T> &v) const 
{
	return (this->size() != v.size() || std::lexicographical_compare(this->begin().t, this->end().t, v.begin().t, v.end().t, _comp_not_equal));
}


Note that this->begin() returns an iterator and its member variable is t

I then try this code :
1
2
3
4
5
6
7
8
9
mVector<int> foo (100, 3);   // Three ints with a value of 100
mVector<int> bar (200, 2);   // Two ints with a value of 200

if (foo==bar) std::cout << "+ foo and bar are equal\n";
if (foo!=bar) std::cout << "+ foo and bar are not equal\n";
if (foo< bar) std::cout << "+ foo is less than bar\n";
if (foo> bar) std::cout << "+ foo is greater than bar\n";
if (foo<=bar) std::cout << "+ foo is less than or equal to bar\n";
if (foo>=bar) std::cout << "+ foo is greater than or equal to bar\n";


The output for my program is :
+ foo and bar are not equal
+ foo is less than bar
+ foo is greater than bar
+ foo is greater than or equal to bar


It should be :
+ foo and bar are not equal
+ foo is less than bar
+ foo is less than or equal to bar


Could anyone help me? Any help would be appreciated.
Thanks.
Last edited on
I think these are optional and not needed I guess.
Mark that as solved now.
Just a question : Can it be done without std::lexicographical_compare?
Topic archived. No new replies allowed.