Click here to Skip to main content
15,923,051 members
Home / Discussions / ATL / WTL / STL
   

ATL / WTL / STL

 
GeneralRe: How to invoke IPimSrcContactNew::Create Pin
benchi200624-Feb-09 14:19
benchi200624-Feb-09 14:19 
GeneralRe: How to invoke IPimSrcContactNew::Create Pin
Stuart Dootson24-Feb-09 21:15
professionalStuart Dootson24-Feb-09 21:15 
Questionabout STL design Pin
followait20-Feb-09 23:06
followait20-Feb-09 23:06 
AnswerRe: about STL design Pin
«_Superman_»21-Feb-09 21:55
professional«_Superman_»21-Feb-09 21:55 
AnswerRe: about STL design Pin
Stuart Dootson22-Feb-09 13:40
professionalStuart Dootson22-Feb-09 13:40 
AnswerRe: about STL design Pin
CPallini22-Feb-09 22:22
mveCPallini22-Feb-09 22:22 
Questionmore on webbrowser control in the tabbrowser sample in wtl 8 Pin
Babil_JR20-Feb-09 4:23
Babil_JR20-Feb-09 4:23 
GeneralRe: more on webbrowser control in the tabbrowser sample in wtl 8 Pin
Alain Rist20-Feb-09 8:39
Alain Rist20-Feb-09 8:39 
QuestionRename VC6 project's configuations Pin
mathewzhao20-Feb-09 3:40
mathewzhao20-Feb-09 3:40 
Questionhow to get a project's active configuration [modified] Pin
mathewzhao18-Feb-09 23:24
mathewzhao18-Feb-09 23:24 
AnswerRe: how to get a project's active configuration Pin
Stuart Dootson19-Feb-09 2:01
professionalStuart Dootson19-Feb-09 2:01 
GeneralRe: how to get a project's active configuration Pin
mathewzhao19-Feb-09 3:08
mathewzhao19-Feb-09 3:08 
GeneralRe: how to get a project's active configuration Pin
Stuart Dootson19-Feb-09 3:17
professionalStuart Dootson19-Feb-09 3:17 
Questioniterator question Pin
followait18-Feb-09 2:51
followait18-Feb-09 2:51 
AnswerRe: iterator question Pin
Nuri Ismail18-Feb-09 3:19
Nuri Ismail18-Feb-09 3:19 
GeneralRe: iterator question Pin
followait18-Feb-09 15:35
followait18-Feb-09 15:35 
GeneralRe: iterator question Pin
Nuri Ismail18-Feb-09 21:31
Nuri Ismail18-Feb-09 21:31 
AnswerRe: iterator question Pin
Stuart Dootson18-Feb-09 8:45
professionalStuart Dootson18-Feb-09 8:45 
AnswerRe: iterator question Pin
Stuart Dootson18-Feb-09 21:45
professionalStuart Dootson18-Feb-09 21:45 
QuestionUse a <set> to sort a <map>? Pin
Kyudos16-Feb-09 15:10
Kyudos16-Feb-09 15:10 
AnswerRe: Use a <set> to sort a <map>? Pin
«_Superman_»16-Feb-09 18:31
professional«_Superman_»16-Feb-09 18:31 
GeneralRe: Use a <set> to sort a <map>? Pin
Kyudos17-Feb-09 8:41
Kyudos17-Feb-09 8:41 
GeneralRe: Use a <set> to sort a <map>? Pin
Stuart Dootson17-Feb-09 20:41
professionalStuart Dootson17-Feb-09 20:41 
GeneralRe: Use a <set> to sort a <map>? Pin
Eytukan22-Feb-09 20:05
Eytukan22-Feb-09 20:05 
AnswerRe: Use a <set> to sort a <map>? [modified] Pin
Stuart Dootson17-Feb-09 9:22
professionalStuart Dootson17-Feb-09 9:22 
[edit]Modified code after actually building and running it...[/edit]

There are lots of ways of doing this. I wouldn't use a set, 'cause it's generally quicker to use a sorted std::vector and then do a std::lower_bound or std::upper_bound to find the relevant item.

What I'd do (have done!) would be to make a secondary index, which is a vector of Info pointers and sort it.

bool OrderOnDistToRef(Info const* l, Info const* r) const { return l->DistToRef < r->DistToRef; }

std::vector<const Info*> index;
for(std::map<LONG, Info>::const_iterator i=m_PtsInfo.begin();i!=m_PtsInfo.end();++i)
{
   index.push_back(&i->second);
}
std::sort(index.begin(), index.end(), OrderOnDistToRef);


Then we can do lookups using something like

Info lookingForStruct;
lookingForStruct.DistToRef = distToRefWeAreLookingFor;
std::vector<const Info*>::const_iterator found = std::lower_bound(index.begin(), index.end(), &lookingForStruct, OrderOnDistToRef);


Alternatively, you could use a Boost Multi-Index[^], which gives you a mappish container with multiple lookups.

Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

modified on Tuesday, February 17, 2009 4:17 PM

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.