boost::trim throwing std::bad_cast exeption with custom basic_string
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 Thanks
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);
It doesn't raise exceptions on MSVC10, so I guess the problem is in the standard library implementation you use.
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);
It doesn't raise exceptions on MSVC10, so I guess the problem is in the standard library implementation you use. Thanks for your reply. I think I made a mistake on providing with the example. It doesn't throw an exception if str is empty. Could you try
On Sat, 22 Jan 2011 20:08:48 +0200
Igor R
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On Sun, 23 Jan 2011 10:08:40 +0200
Igor R
typedef basic_string<int> ustring; ustring str(2,0x61); boost::trim(str);
this is throwing an exception. I tried it with boost 1.40 and 1.42.
It doesn't throw if compiled with MSVC10.
BTW, which version of boost you are testing on?
1.45
It is still throwing an exception with boost 1.45. Since it's working fine with MSVC10 then something must be wrong with gcc. Here are the combinations which I tested so far: gcc 4.3.4 , boost 1.40 gcc 4.4.5 , boost 1.42 and 1.45 Any help will be appriciated Thanks
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
It is still throwing an exception with boost 1.45. Since it's working fine with MSVC10 then something must be wrong with gcc. Here are the combinations which I tested so far:
gcc 4.3.4 , boost 1.40 gcc 4.4.5 , boost 1.42 and 1.45
The problem is not in gcc, but somewhere in std/crt. The exception is thrown by std::use_facet() function, which doesn't find the locale you passed to trim(). Since, you don't actually pass any locale, it uses the global one, so I don't understand why it doesn't find it... Anyway, try passing some locale explicitly, and see what happens: boost::trim(str, std::locale("English_UK"));
On Sun, 23 Jan 2011 18:28:21 +0200
Igor R
It is still throwing an exception with boost 1.45. Since it's working fine with MSVC10 then something must be wrong with gcc. Here are the combinations which I tested so far:
gcc 4.3.4 , boost 1.40 gcc 4.4.5 , boost 1.42 and 1.45
The problem is not in gcc, but somewhere in std/crt. The exception is thrown by std::use_facet() function, which doesn't find the locale you passed to trim(). Since, you don't actually pass any locale, it uses the global one, so I don't understand why it doesn't find it... Anyway, try passing some locale explicitly, and see what happens: boost::trim(str, std::locale("English_UK"));
Now it's throwing another exception: locale::facet::_S_create_c_locale name not valid. I tried different name like "English_UK", "en_US", "en_GB". All of them gave me the same exception.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
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
participants (3)
-
Arash Abghari
-
Igor R
-
Viatcheslav.Sysoltsev@h-d-gmbh.de