Click here to Skip to main content
15,896,557 members
Home / Discussions / ATL / WTL / STL
   

ATL / WTL / STL

 
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

QuestionWhy basic_string doesn't support back(), but vector do? Pin
followait13-Feb-09 17:52
followait13-Feb-09 17:52 
AnswerRe: Why basic_string doesn't support back(), but vector do? Pin
«_Superman_»13-Feb-09 19:44
professional«_Superman_»13-Feb-09 19:44 
AnswerRe: Why basic_string doesn't support back(), but vector do? Pin
Stuart Dootson15-Feb-09 4:03
professionalStuart Dootson15-Feb-09 4:03 
QuestionHow do we Inherit struct from another struct in IDL file Pin
Gopal_Kanchana11-Feb-09 23:44
Gopal_Kanchana11-Feb-09 23:44 
QuestionHow to trap Excel 2007 cell events using ATL addin Pin
SNI11-Feb-09 2:18
SNI11-Feb-09 2:18 
QuestionProblem with ATL COM Dll.... Firing event in thread Pin
chetanjoshi910-Feb-09 20:15
chetanjoshi910-Feb-09 20:15 
AnswerRe: Problem with ATL COM Dll.... Firing event in thread Pin
Stuart Dootson10-Feb-09 22:56
professionalStuart Dootson10-Feb-09 22:56 
GeneralRe: Problem with ATL COM Dll.... Firing event in thread Pin
chetanjoshi910-Feb-09 23:06
chetanjoshi910-Feb-09 23:06 
GeneralRe: Problem with ATL COM Dll.... Firing event in thread Pin
Stuart Dootson11-Feb-09 0:46
professionalStuart Dootson11-Feb-09 0:46 
GeneralRe: Problem with ATL COM Dll.... Firing event in thread Pin
chetanjoshi911-Feb-09 0:52
chetanjoshi911-Feb-09 0:52 
GeneralRe: Problem with ATL COM Dll.... Firing event in thread Pin
Stuart Dootson11-Feb-09 0:59
professionalStuart Dootson11-Feb-09 0:59 
GeneralRe: Problem with ATL COM Dll.... Firing event in thread Pin
chetanjoshi911-Feb-09 1:26
chetanjoshi911-Feb-09 1:26 
GeneralRe: Problem with ATL COM Dll.... Firing event in thread Pin
Stuart Dootson11-Feb-09 1:56
professionalStuart Dootson11-Feb-09 1:56 
GeneralRe: Problem with ATL COM Dll.... Firing event in thread Pin
chetanjoshi911-Feb-09 2:19
chetanjoshi911-Feb-09 2:19 
GeneralRe: Problem with ATL COM Dll.... Firing event in thread Pin
Stuart Dootson11-Feb-09 2:26
professionalStuart Dootson11-Feb-09 2:26 
QuestionHelp required in writing a class to write/read log data to XML files Pin
Rennie769-Feb-09 0:38
Rennie769-Feb-09 0:38 
AnswerRe: Help required in writing a class to write/read log data to XML files Pin
Stuart Dootson9-Feb-09 2:33
professionalStuart Dootson9-Feb-09 2:33 

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.