|
-
Oct 31st, 2003, 04:53 PM
#1
Thread Starter
Frenzied Member
Template?
I was wondering if there was an easier way to this maybe with a template?
I have a bunch of structs that have one common element. I use that common element to do a std::lower_bound on a vector of these structs. So for example:
Code:
struct a
{
std::string sX;
std::string sName;
};
struct b
{
std::string sX;
std::string sLocation;
};
struct c
{
std::string sX;
std::string sPeople;
};
struct A_LESS
{
bool operator () (const a& lhs , const a& rhs)
{
if (lhs.sX.size() != rhs.sX.size())
return lhs.sX.size() > rhs.sX.size();
return lhs.sX < rhs.sX;
}
};
vector<a> vecA;
...all the rest are vectors, then data is read in. Then in a function
b b_temp.sX = "xyz";
vector<a>::iterator it = std::lower_bound(vecA.begin(),
vecA.end(),
b_tmp,A_LESS());
My question is that all the structs have sX in them. Is it possible to create a template or something instead of having to make a new less than struct for each of the types of structs (a,b,c), so I can do std::lower_bound against all the structs (a,b,c)?
Last edited by Technocrat; Oct 31st, 2003 at 04:57 PM.
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

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
|