RE: [Dev-C++] Optimizing using the STL
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Abhijit S. <mu...@gm...> - 2003-07-25 13:54:57
|
Hello, David.
> Any suggestions on how I can optimized the following
> function?
>
> void pc_char::write_to_all_pc(string to_send, bool
> add_eoln)
> {
> map<string, pc_char *>::iterator i =
> current_players.begin();
>
> while (i != current_players.end()) {
> (*i).second->write_to_player(to_send, add_eoln);
> }
> }
>
> I was hoping to use for_each but kept coming across the
> problem of "How the hell am I going to pass the arguments
> to write_to_player?"
I'm not exactly an STL hacker, so I wouldn't know if there's a more elegant
solution, but here's my idea:
You can maintain a namespace with pointers to arguments for
write_to_player() and empty-out the arg-list of write_to_player() (and
probably write an inline wrapper to map from arg-list to this namespace for
normal calls). Then intially set up to_send and add_eoln in that namespace
and call for_each() with begin and end. This will work here because the
arguments are common.
--
Abhijit Shylanath
Homepage: http://mudeth.tripod.com/
|