Click here to Skip to main content
16,006,531 members
Home / Discussions / ATL / WTL / STL
   

ATL / WTL / STL

 
GeneralRe: amazon upload need help... Pin
Steve S19-May-04 22:29
Steve S19-May-04 22:29 
GeneralRe: amazon upload need help... Pin
Sumit Kapoor19-May-04 22:47
Sumit Kapoor19-May-04 22:47 
GeneralRe: amazon upload need help... Pin
Steve S20-May-04 4:34
Steve S20-May-04 4:34 
GeneralRe: amazon upload need help... Pin
Sumit Kapoor20-May-04 4:42
Sumit Kapoor20-May-04 4:42 
Questionhow to diasable a button Pin
mike shen19-May-04 16:37
mike shen19-May-04 16:37 
Generalusing for_each Pin
paulb19-May-04 15:13
paulb19-May-04 15:13 
GeneralRe: using for_each Pin
valikac19-May-04 18:36
valikac19-May-04 18:36 
GeneralRe: using for_each Pin
Andrew Walker19-May-04 22:10
Andrew Walker19-May-04 22:10 
Yes, it is doable, but not using 'clean' STL design ideas. remember that the type of the element in the map is std::pair<string,ofstream*>, not just ofstream or ofstream*, so you need to compensate for that. The easiest way I can think of is to use lambda expressions (see boost::lambda for a comprehensive library).

Personally, I feel that lambda libraries are shakey ground at the moment. Most developers have enough trouble reading normal STL constructs without adding in strange things like '_1'and '_2' - but it depends on how comfortable with STL you and your co-workers are.

Just as an aside, are you sure that you really want to do this? Assuming that you dynamically creating the files why don't you rely upon the destructors to close the files for you - if this is the behavior that you want use boost::shared_ptr to keep a reference counter handle to the files, and when the map goes out of scope, all the files will be taken with it. The only other reason I can think that you would want to do this is to reuse the files, if you are doing this make sure that you test thoroughly Herb Sutter (the convenor of the C++ standards committee) documented some interesting 'features' (read: issues) of ofstream's after they have recycled in a recent issue of the C/C++ Users Journal.

After all that, if you're prepared to compromise on a 'dirty' rewrite for_each to work nicely with pairs, use the normal loop or try the following:

void closer(const std::pair<string,ofstream*>& toClose)
{
    toClose.second->close();
}

for_each(outputFiles.begin(), outputFiles.end(), closer);

In this case I think your original loop really does make things a lot clearer than it would otherwise be.


If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts you aim;
Yours is the Earth and everything that's in it.

Rudyard Kipling

GeneralRe: using for_each Pin
paulb20-May-04 13:14
paulb20-May-04 13:14 
GeneralRe: using for_each Pin
Jörgen Sigvardsson23-May-04 12:01
Jörgen Sigvardsson23-May-04 12:01 
GeneralRe: using for_each Pin
Andrew Walker23-May-04 20:05
Andrew Walker23-May-04 20:05 
GeneralRe: using for_each Pin
Jörgen Sigvardsson24-May-04 10:56
Jörgen Sigvardsson24-May-04 10:56 
GeneralATL &amp; ActiveX &amp; HTTP Session Pin
VictorPr19-May-04 2:37
VictorPr19-May-04 2:37 
GeneralATL DLL not showing in COM+ Pin
parkerpkthn18-May-04 11:18
parkerpkthn18-May-04 11:18 
GeneralCOM Server/Service Pin
shekar_raja17-May-04 18:26
shekar_raja17-May-04 18:26 
GeneralRe: COM Server/Service Pin
Anonymous17-May-04 19:03
Anonymous17-May-04 19:03 
GeneralRe: COM Server/Service Pin
shekar_raja18-May-04 15:13
shekar_raja18-May-04 15:13 
Generaladding property to ATL HTML control Pin
Abhi Lahare16-May-04 22:16
Abhi Lahare16-May-04 22:16 
Generalset activeX property using param.in HTML page Pin
Abhi Lahare18-May-04 3:58
Abhi Lahare18-May-04 3:58 
QuestionSliders and Editboxes in WTL??? Pin
Member 15847216-May-04 20:15
Member 15847216-May-04 20:15 
GeneralWTL - 7.5 Released - Open Source Pin
Ed Preston15-May-04 5:50
Ed Preston15-May-04 5:50 
GeneralRe: WTL - 7.5 Released - Open Source Pin
Jörgen Sigvardsson15-May-04 12:57
Jörgen Sigvardsson15-May-04 12:57 
GeneralRe: WTL - 7.5 Released - Open Source Pin
_Magnus_16-May-04 23:38
_Magnus_16-May-04 23:38 
GeneralRe: WTL - 7.5 Released - Open Source Pin
Jörgen Sigvardsson23-May-04 12:02
Jörgen Sigvardsson23-May-04 12:02 
Generalafter installing xp service pack 1 and latest windows update. Pin
ekklesia14-May-04 19:59
ekklesia14-May-04 19: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.