operator <

hi my friend
ok as you know in header file string declare
1
2
3
4
5
6
7
8
9
template<class _Elem,
	class _Traits,
	class _Alloc> inline
	bool __CLRCALL_OR_CDECL operator<(
		const basic_string<_Elem, _Traits, _Alloc>& _Left,
		const basic_string<_Elem, _Traits, _Alloc>& _Right)
	{	// test if string < string
	return (_Left.compare(_Right) < 0);
	}

and if everywhere you compare two string then use of this code.ok how can i write operator < to compare two string so that everywhere use of this not operator < in string header file !!! note : my compiler is vs 2008 pro NOT TEAM SYSTEM.
for exm if i want compare ignore_case two string in sort stl algorithm without send pred to this function and use automatic my operator < .
tnx and so sorry if my eng language is too bad :D :D

my operator < such as :
1
2
3
4
5
6
7
8
9
bool ignore_case(char l, char r)
{
	return tolower( l ) < tolower( r );
}

bool operator <(const string &left, const string &right) const 
{
	return lexicographical_compare(left.begin(), left.end(), right.begin(), right.end(), ignore_case);
}

how to change operator < that all campare of two string use this automatically ?
Last edited on
You'll need to put it in the std namespace, then as long as the compiler sees your function, it will be a better match than the template version and be selected by the compiler.
tnx a lot my friend you are too profassional :))
Topic archived. No new replies allowed.