Click here to Skip to main content
16,011,428 members
Home / Discussions / ATL / WTL / STL
   

ATL / WTL / STL

 
GeneralRe: STL Algorithms Pin
Zac Howland14-Sep-06 3:17
Zac Howland14-Sep-06 3:17 
GeneralRe: STL Algorithms Pin
Nemanja Trifunovic15-Sep-06 4:43
Nemanja Trifunovic15-Sep-06 4:43 
GeneralRe: STL Algorithms Pin
Zac Howland15-Sep-06 5:26
Zac Howland15-Sep-06 5:26 
GeneralRe: STL Algorithms Pin
Stuart Dootson15-Sep-06 5:43
professionalStuart Dootson15-Sep-06 5:43 
GeneralRe: STL Algorithms Pin
Rob Caldecott17-Sep-06 23:49
Rob Caldecott17-Sep-06 23:49 
GeneralRe: STL Algorithms Pin
Stephen Hewitt18-Sep-06 0:34
Stephen Hewitt18-Sep-06 0:34 
GeneralRe: STL Algorithms Pin
Rob Caldecott18-Sep-06 4:06
Rob Caldecott18-Sep-06 4:06 
GeneralRe: STL Algorithms Pin
Stephen Hewitt18-Sep-06 13:48
Stephen Hewitt18-Sep-06 13:48 
This is because BOOST_FOREACH is a macro. See here[^]. There are many ways to fix this including a typedef or an extra pair of brackets, but in this case the best is the following:
typedef std::map<int, int> collection_t;
collection_t m;
BOOST_FOREACH(collection_t::value_type p, m)
{
}


In general, with of without using BOOST_FOREACH, it's best to use a typedef to define an alias to the collection type, here collection_t. This allows us to change the type of collection used in one place. Once this is done we use the value_type typedef which is in every STL collection.

I'd probably use a reference, const if possible, like this:
typedef std::map<int, int> collection_t;
collection_t m;
BOOST_FOREACH(const collection_t::value_type &p, m)
{
}


In both these examples the actual type name of the collection is only mentioned in one place and so can be easily changed. When for hash maps are added to STL, for example, this would mean that you can switch between a hash map or binary tree by changing only one line.

Steve

GeneralRe: STL Algorithms Pin
Rob Caldecott19-Sep-06 0:03
Rob Caldecott19-Sep-06 0:03 
QuestionHyperlinks on MenuItems Pin
PrafullaT11-Sep-06 22:11
PrafullaT11-Sep-06 22:11 
AnswerRe: Hyperlinks on MenuItems Pin
Jörgen Sigvardsson12-Sep-06 1:44
Jörgen Sigvardsson12-Sep-06 1:44 
AnswerRe: Hyperlinks on MenuItems Pin
Hamid_RT15-Sep-06 21:42
Hamid_RT15-Sep-06 21:42 
Questionfopen problem in ATL Pin
_tasleem8-Sep-06 4:07
_tasleem8-Sep-06 4:07 
AnswerRe: fopen problem in ATL Pin
Rob Caldecott8-Sep-06 4:30
Rob Caldecott8-Sep-06 4:30 
GeneralRe: fopen problem in ATL Pin
Jörgen Sigvardsson11-Sep-06 2:25
Jörgen Sigvardsson11-Sep-06 2:25 
GeneralRe: fopen problem in ATL Pin
Stephen Hewitt11-Sep-06 14:46
Stephen Hewitt11-Sep-06 14:46 
GeneralRe: fopen problem in ATL Pin
Jörgen Sigvardsson11-Sep-06 15:06
Jörgen Sigvardsson11-Sep-06 15:06 
GeneralRe: fopen problem in ATL Pin
_tasleem12-Sep-06 3:02
_tasleem12-Sep-06 3:02 
AnswerRe: fopen problem in ATL Pin
Stuart Dootson11-Sep-06 8:30
professionalStuart Dootson11-Sep-06 8:30 
GeneralRe: fopen problem in ATL Pin
_tasleem12-Sep-06 23:58
_tasleem12-Sep-06 23:58 
QuestionAllow placement on my control in design-time Pin
Tilir7-Sep-06 20:08
Tilir7-Sep-06 20:08 
QuestionProblem: WTL::CString exchange between pure WTL DLLs (note: no MFC intermixing) Pin
x-b7-Sep-06 0:41
x-b7-Sep-06 0:41 
AnswerRe: Problem: WTL::CString exchange between pure WTL DLLs (note: no MFC intermixing) Pin
Michael Dunn9-Sep-06 17:31
sitebuilderMichael Dunn9-Sep-06 17:31 
GeneralRe: Problem: WTL::CString exchange between pure WTL DLLs (note: no MFC intermixing) Pin
x-b10-Sep-06 22:34
x-b10-Sep-06 22:34 
GeneralRe: Problem: WTL::CString exchange between pure WTL DLLs (note: no MFC intermixing) Pin
Michael Dunn11-Sep-06 7:28
sitebuilderMichael Dunn11-Sep-06 7:28 

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.