STL and member functions ???
-
I'm working on a trace utility, mainly to extend my knowledge of IOStreams and STL. I have a map to keep track of a number of edit windows, which all take the same position and are sown based on a tab control. map m_TraceMap; Now, I hide all my windows before showing the one selected, like this: void HideWindow(std::pair p) { CTraceWnd * pWnd = p.second; pWnd->ShowWindow(SW_HIDE); } void CTabView::OnSelchangeTab(NMHDR* pNMHDR, LRESULT* pResult) { std::for_each(m_TraceMap.begin(), m_TraceMap.end(), HideWindow); // etc, etc. Now I have two questions. 1. How can I make HideWindow a member function of CTabView ? I've tried mem_funxxx stuff, to no avail, and spent a good amount of time reading 'Generic Programming and the STL', also without any success. 2. Better yet, is there a way I can call ShowWindow(SW_HIDE) directly, OR add a HideWindow function that does this to CTraceWnd, and call that ? Thanks to anyone who answers. Christian After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOz
I live in Bob's HungOut now
-
I'm working on a trace utility, mainly to extend my knowledge of IOStreams and STL. I have a map to keep track of a number of edit windows, which all take the same position and are sown based on a tab control. map m_TraceMap; Now, I hide all my windows before showing the one selected, like this: void HideWindow(std::pair p) { CTraceWnd * pWnd = p.second; pWnd->ShowWindow(SW_HIDE); } void CTabView::OnSelchangeTab(NMHDR* pNMHDR, LRESULT* pResult) { std::for_each(m_TraceMap.begin(), m_TraceMap.end(), HideWindow); // etc, etc. Now I have two questions. 1. How can I make HideWindow a member function of CTabView ? I've tried mem_funxxx stuff, to no avail, and spent a good amount of time reading 'Generic Programming and the STL', also without any success. 2. Better yet, is there a way I can call ShowWindow(SW_HIDE) directly, OR add a HideWindow function that does this to CTraceWnd, and call that ? Thanks to anyone who answers. Christian After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOz
I live in Bob's HungOut now
class MyClass : public CTabView { public: MyClass() {} void HideWindow() { CTabView::ShowWindow(SW_SHOW); }; }; // this seems like it should be a template of some kind void HideWindow(const std::pair& v) { MyClass& blah = const_cast(v.second); blah.HideWindow(); } void main() { std::map blah; std::for_each(blah.begin(), blah.end(), HideWindow); }
-
class MyClass : public CTabView { public: MyClass() {} void HideWindow() { CTabView::ShowWindow(SW_SHOW); }; }; // this seems like it should be a template of some kind void HideWindow(const std::pair& v) { MyClass& blah = const_cast(v.second); blah.HideWindow(); } void main() { std::map blah; std::for_each(blah.begin(), blah.end(), HideWindow); }
Thanks, I'm sure this will work, and the way I'm doing it now works, too, but I want to get rid of the global function altogether and replace it with a member function, either of the class held in the second part of the pair, or in the class calling the function. Christian After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOz
I live in Bob's HungOut now
-
class MyClass : public CTabView { public: MyClass() {} void HideWindow() { CTabView::ShowWindow(SW_SHOW); }; }; // this seems like it should be a template of some kind void HideWindow(const std::pair& v) { MyClass& blah = const_cast(v.second); blah.HideWindow(); } void main() { std::map blah; std::for_each(blah.begin(), blah.end(), HideWindow); }
void CTabView::HideWindow(std::pair p) { CTraceWnd * pWnd = p.second; pWnd->ShowWindow(SW_HIDE); } void CTabView::OnSelchangeTab(NMHDR* pNMHDR, LRESULT* pResult) { std::for_each(m_TraceMap.begin(), m_TraceMap.end(), std::mem_fun_ref(&CTabView::HideWindow)); but I get this error: error C2784: 'class std::mem_fun_ref_t<_R,_Ty> __cdecl std::mem_fun_ref(_R (__thiscall _Ty::*)(void))' : could not deduce template argument for '' from 'void (__thiscall CTabView::*)(struct std::p air)' I thought maybe mem_fun1_ref, but things just got worse. I tried adding the function to CTraceWnd, but that was worse again.... Christian After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOz
I live in Bob's HungOut now
-
I'm working on a trace utility, mainly to extend my knowledge of IOStreams and STL. I have a map to keep track of a number of edit windows, which all take the same position and are sown based on a tab control. map m_TraceMap; Now, I hide all my windows before showing the one selected, like this: void HideWindow(std::pair p) { CTraceWnd * pWnd = p.second; pWnd->ShowWindow(SW_HIDE); } void CTabView::OnSelchangeTab(NMHDR* pNMHDR, LRESULT* pResult) { std::for_each(m_TraceMap.begin(), m_TraceMap.end(), HideWindow); // etc, etc. Now I have two questions. 1. How can I make HideWindow a member function of CTabView ? I've tried mem_funxxx stuff, to no avail, and spent a good amount of time reading 'Generic Programming and the STL', also without any success. 2. Better yet, is there a way I can call ShowWindow(SW_HIDE) directly, OR add a HideWindow function that does this to CTraceWnd, and call that ? Thanks to anyone who answers. Christian After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOz
I live in Bob's HungOut now
Create a from std::unary_function derived helper class then it should work. For map for_each functors, it should look like this, remember the first pair argument must be const (i think). I assume your maps' pairs' first argument is an int. class hidewindow_functor : public std::unary_function< std::pair<int const,CWnd*>, void> { public: void operator() (std::pair<int const,CWnd*>& target) const { target.second->ShowWindow(SW_HIDE); } }; Cheers, Alexander Berthold
-
void CTabView::HideWindow(std::pair p) { CTraceWnd * pWnd = p.second; pWnd->ShowWindow(SW_HIDE); } void CTabView::OnSelchangeTab(NMHDR* pNMHDR, LRESULT* pResult) { std::for_each(m_TraceMap.begin(), m_TraceMap.end(), std::mem_fun_ref(&CTabView::HideWindow)); but I get this error: error C2784: 'class std::mem_fun_ref_t<_R,_Ty> __cdecl std::mem_fun_ref(_R (__thiscall _Ty::*)(void))' : could not deduce template argument for '' from 'void (__thiscall CTabView::*)(struct std::p air)' I thought maybe mem_fun1_ref, but things just got worse. I tried adding the function to CTraceWnd, but that was worse again.... Christian After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOz
I live in Bob's HungOut now
-
Try making a "void HideWindow ()" method in CTraceWnd. Then "std::mem_fun_ref (CTraceWnd::HideWindow)" should work. Tim Smith Descartes Systems Sciences, Inc.
I had done that previously, and I get this: void CTabView::OnSelchangeTab(NMHDR* pNMHDR, LRESULT* pResult) { std::for_each(m_TraceMap.begin(), m_TraceMap.end(), std::mem_fun_ref(CTraceWnd::HideWindow)); void CTraceWnd::HideWindow(std::pair p) { p.second->ShowWindow(SW_HIDE); } error C2784: 'class std::mem_fun_ref_t<_R,_Ty> __cdecl std::mem_fun_ref(_R (__thiscall _Ty::*)(void))' : could not deduce template argument for '' from 'void (__thiscall CTraceWnd::*)(struct std:: pair)' Tried mem_fun1_ref as well. I don't think this can work as I need to pull second out of the pair first, which requires some non-standard stuff found in STLPort, etc. I will install STLPort tonight. Christian After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOz
I live in Bob's HungOut now
-
Create a from std::unary_function derived helper class then it should work. For map for_each functors, it should look like this, remember the first pair argument must be const (i think). I assume your maps' pairs' first argument is an int. class hidewindow_functor : public std::unary_function< std::pair<int const,CWnd*>, void> { public: void operator() (std::pair<int const,CWnd*>& target) const { target.second->ShowWindow(SW_HIDE); } }; Cheers, Alexander Berthold
Thanks - although not quite what I was after, I'm now convinced I need some non standard STL stuff from STLPort to make it work the way I want. However, it only works if I make CWnd above CTraceWnd, can you tell me why STL cannot do the cast ? Thanks. Christian After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOz
I live in Bob's HungOut now