Click here to Skip to main content
15,885,032 members
Home / Discussions / ATL / WTL / STL
   

ATL / WTL / STL

 
GeneralRe: Store STL iterator in CListBox Pin
Richard MacCutchan17-Jan-12 5:22
mveRichard MacCutchan17-Jan-12 5:22 
GeneralRe: Store STL iterator in CListBox Pin
LionAM17-Jan-12 9:09
LionAM17-Jan-12 9:09 
GeneralRe: Store STL iterator in CListBox Pin
Richard MacCutchan17-Jan-12 9:31
mveRichard MacCutchan17-Jan-12 9:31 
AnswerRe: Store STL iterator in CListBox Pin
«_Superman_»18-Jan-12 18:23
professional«_Superman_»18-Jan-12 18:23 
GeneralRe: Store STL iterator in CListBox Pin
LionAM19-Jan-12 9:04
LionAM19-Jan-12 9:04 
AnswerRe: Store STL iterator in CListBox Pin
Orjan Westin19-Jan-12 4:24
professionalOrjan Westin19-Jan-12 4:24 
GeneralRe: Store STL iterator in CListBox Pin
LionAM19-Jan-12 8:54
LionAM19-Jan-12 8:54 
GeneralRe: Store STL iterator in CListBox Pin
Orjan Westin19-Jan-12 23:38
professionalOrjan Westin19-Jan-12 23:38 
In that case, you could store a pointer rather than an iterator to the element, by taking the address of the value the iterator points to.

C++
int* pointer_in_listbox = &(*it);
listBox.SetItemDataPtr(index, pointer_in_listbox);


This would require an extra step to retrieve the iterator, using a custom predicate:

C++
struct ptr_cmp
{
  // Pointer we're looking for
  const int* ptr;

  // Constructor
  ptr_cmp(const int* p)
  : ptr(p)
  {}

  // Predicate function
  bool operator()(const int& i)
  {
    return (&i == ptr);
  }
};


This lets you use the std::find_if algorihtm (remember to #include <algorithm>):

C++
// Declare a predicate with the item we're looking for
int* pointer_from_listbox = static_cast<int*>(listBox.GetItemDataPtr(index));
ptr_cmp comparer(pointer_from_listbox);

// Find the corresponding iterator
std::list<int>::iterator it = std::find_if(l.begin(), l.end(), comparer);


That ought to work. It is slower than direct access via the iterator, but should not be noticeable in a GUI context.
GeneralRe: Store STL iterator in CListBox Pin
LionAM20-Jan-12 11:04
LionAM20-Jan-12 11:04 
AnswerRe: Store STL iterator in CListBox Pin
Emilio Garavaglia25-Jan-12 21:22
Emilio Garavaglia25-Jan-12 21:22 
AnswerRe: Store STL iterator in CListBox Pin
nv314-Mar-12 13:05
nv314-Mar-12 13:05 
GeneralRe: Store STL iterator in CListBox Pin
LionAM16-Mar-12 12:34
LionAM16-Mar-12 12:34 
QuestionHow to get the address of resource data in an execute file? Pin
whiteclouds15-Jan-12 21:49
whiteclouds15-Jan-12 21:49 
AnswerRe: How to get the address of resource data in an execute file? Pin
Richard MacCutchan15-Jan-12 23:00
mveRichard MacCutchan15-Jan-12 23:00 
GeneralRe: How to get the address of resource data in an execute file? Pin
whiteclouds16-Jan-12 20:59
whiteclouds16-Jan-12 20:59 
QuestionBoost iterators in TR1/C++11 Pin
Orjan Westin13-Jan-12 5:37
professionalOrjan Westin13-Jan-12 5:37 
Questioncompression/decompression using GZip.exe(3rd party) Pin
KASR111-Jan-12 0:13
KASR111-Jan-12 0:13 
AnswerRe: compression/decompression using GZip.exe(3rd party) Pin
Richard MacCutchan11-Jan-12 2:39
mveRichard MacCutchan11-Jan-12 2:39 
AnswerRe: compression/decompression using GZip.exe(3rd party) Pin
Albert Holguin17-Jan-12 9:30
professionalAlbert Holguin17-Jan-12 9:30 
QuestionFireEvent method not returning cancelchange status correctly. Pin
keloth879-Jan-12 22:35
keloth879-Jan-12 22:35 
QuestionVS2010 CLR double to String, String to double MSVC/C++ methods? Pin
meace12345-Jan-12 22:14
meace12345-Jan-12 22:14 
AnswerRe: VS2010 CLR double to String, String to double MSVC/C++ methods? Pin
Richard MacCutchan5-Jan-12 23:13
mveRichard MacCutchan5-Jan-12 23:13 
GeneralRe: VS2010 CLR double to String, String to double MSVC/C++ methods? Pin
meace12345-Jan-12 23:25
meace12345-Jan-12 23:25 
GeneralRe: VS2010 CLR double to String, String to double MSVC/C++ methods? Pin
Richard MacCutchan5-Jan-12 23:54
mveRichard MacCutchan5-Jan-12 23:54 
GeneralRe: VS2010 CLR double to String, String to double MSVC/C++ methods? Pin
meace12345-Jan-12 23:59
meace12345-Jan-12 23:59 

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.