Boost logo

Boost Users :

Subject: Re: [Boost-users] boost::trim throwing std::bad_cast exeption with custom basic_string
From: Viatcheslav.Sysoltsev_at_[hidden]
Date: 2011-01-24 05:00:51


> Hi,
>
> I have a custom basic_string as follows:
>
> typedef basic_string<unsigned int> ustring;
>
> so if I pass an instance of ustring to boost:trim it throws an
> std::bad_cast exception.
>
> ustring str;
> boost::trim(str);
>
> The exception comes from here:
>
> include/boost/algorithm/string/detail/classification.hpp:45
> return std::use_facet< std::ctype<CharT> >(m_Locale).is( m_Type, Ch );
>
> It does not matter what character type I use for basic_string, It throws
> the exception for anything but char and wchar_t. Document mentions "A
> string is not restricted to std::basic_string and character does not
> have to be char or wchar_t, although these are most common candidates",
> So I assume, It must work with unsigned int or other types.
>
> Here is the system spec:
>
> boost: 1.40
> gcc: 4.3.4
> OS: Debian Lenny 64bit
>

Hi,

openSuse11.1, gcc 4.3, issue reproducible.

I do not know STL so well, but scanning the internet forums I would rather
suppose gcc's STL implementation supports only char and whar_t for facet
functionality. It might come from char and wchar_t specialization which
are down to libc calls, so it might just not be a backend variant for
other types. Presumably you could provide ctype spezialization for your
character type like these for char and wchar_t in locale_facets.h and then
it will work.. Sorry if I am talking nonsense, just my thoughts.

-- Slava


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