Boost logo

Boost Users :

From: Joshua Little (ljoshua_at_[hidden])
Date: 2004-02-08 15:19:52


todd wrote:

>On Sat, 07 Feb 2004 23:12:58 -0600, Joshua Little wrote
>
>
>>LoggerMap::iterator i = loggers.find(logger);
>>if (!(*i).second.get()) {
>>
>>
>
>If logger doesn't already exist in loggers, then i will be loggers.end().
>Dereferencing end() is undefined. Use this for your conditional instead:
>
>if(i != loggers.end())
>
>Or, if you want to gain speed, do this:
>
>boost::shared_ptr<Logger> LoggerFactory::getInstance(std::string& logger)
>{
> boost::shared_ptr<Logger>& TheLoggerRef = loggers[logger];
> if(!TheLoggerRef.get())
> TheLoggerRef.reset(new Logger());
> return TheLoggerRef;
>}
>
>This version searches the map only once.
>
>find() doesn't add entries, but the array operator does.
>
>Todd
>
>
Thanks Todd, now that I see what I did wrong I wonder why I didn't see
it in the first place :)
Joshua.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net