|
Boost : |
From: Sebastian Redl (sebastian.redl_at_[hidden])
Date: 2006-07-20 11:41:08
David Manura wrote:
> // Operation
> template<typename CharT>
> bool operator()( CharT Ch ) const
> {
>- return std::use_facet< std::ctype<CharT> >(m_Locale).is(
>m_Type, Ch );
>+ static const std::ctype<CharT> & data = std::use_facet<
>std::ctype<CharT> >(m_Locale);
>+ return data.is( m_Type, Ch );
> }
>
>
That is most definitely a bug waiting to pounce. m_Locale is specific to
each instance. The static variable inside the member function is the
same for all instances.
The bug hits when somebody uses this functor with two different locales.
The first object to invoke operator() will work fine - the second (and
each subsequent) will mysteriously use the locale of the first.
If you want to cache the ctype facet, do it as a class variable, perhaps
in the constructor.
Sebastian Redl
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk