Topic: equal_range on container of pointers
Author: mojmir <svobodamo@gmail.com>
Date: Wed, 7 Jan 2009 10:19:06 CST Raw View
i'd like to do query on a sorted container like
std::vector<std::pair<int, int> *> ctr;
and find lower and upper bound for pair (1,*) for example, where
asterisk denotes "anything".
i am a bit puzzled by the interface of equal_range in the case of
elements being pointers, could you please give me a hint?
best regards,
mojmir
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: "Joe Smith" <unknown_kev_cat@hotmail.com>
Date: Wed, 7 Jan 2009 13:22:40 CST Raw View
"mojmir" <svobodamo@gmail.com>:
> i'd like to do query on a sorted container like
> std::vector<std::pair<int, int> *> ctr;
> and find lower and upper bound for pair (1,*) for example, where
> asterisk denotes "anything".
>
> i am a bit puzzled by the interface of equal_range in the case of
> elements being pointers, could you please give me a hint?
This is not the best group to post such questions to. In the future you
should post these kinds of questions to comp.lang.c++ or
comp.lang.c++.moderated
Code like the following should work:
#include <algorithm>
#include <vector>
bool comp_pair_first(std::pair<int,int>* lhs,
std::pair<int,int>* rhs)
{ return (lhs->first < rhs->first); }
int main()
{
std::vector<std::pair<int,int>*> vec;
std::pair<int,int> one(1,0);
//fill vector and sort it.
std::pair<
std::vector<std::pair<int,int>*>::iterator,
std::vector<std::pair<int,int>*>::iterator>
result = std::equal_range(
vec.begin(),
vec.end(),
&one,
comp_pair_first);
}
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]