|
-
Feb 25th, 2004, 01:05 PM
#1
Thread Starter
Frenzied Member
Template?
I asked this before but never really got an answer. So I will try again
I have a std::vector that I search using lower_bound(). To do this I have a struct with a () operator like so:
Code:
struct LM_LESS
{
bool operator () (const LMABREP& lhs , const LMABREP& rhs)
{
if (lhs.sLID.size() != rhs.sLID.size())
return lhs.sLID.size() > rhs.sLID.size();
return lhs.sLID < rhs.sLID;
}
};
LMABREP struct looks like:
Code:
struct LMABREP
{
string sLID;
string sStreetNumber;
string sStreet;
string sStreetSufix;
string sStreetPrefix;
};
So basically sLID contains a number and I am looking for it using lower_bound(). The reason being is there is a possible repeat.
My question is can I turn my operator () into a template because I use functions like this a lot with many different vectors with many different structs. I really dont want to have to write a new () every time I use a different struct.
MSVS 6, .NET & .NET 2003 Pro
I HATE MSDN with .NET & .NET 2003!!!
Check out my sites:
http://www.filthyhands.com
http://www.techno-coding.com

-
Feb 26th, 2004, 07:10 AM
#2
Do all of your structs have this member? Then you can:
Code:
template <typename T>
struct LM_LESS
{
bool operator () (const T& lhs , const T& rhs)
{
if (lhs.sLID.size() != rhs.sLID.size())
return lhs.sLID.size() > rhs.sLID.size();
return lhs.sLID < rhs.sLID;
}
};
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|