|
Boost Users : |
From: Ovanes Markarian (om_boost_at_[hidden])
Date: 2007-04-26 03:50:40
Hello Joaquín,
now I found the failure, to the problem described in message
http://lists.boost.org/boost-users/2007/04/27211.php with std::string as a key not being found.
The problem in my case was that I use Xalan to parse XML and have to convert string to single byte
characters. Since std::string has some build in caching to improve performance and I decode double
byte string (XalanDOMString) as follows:
std::string get_string(XalanDOMString const& str)
{
XalanDOMString::CharVectorType v;
str.transcode(v);
return std::string(v.begin(), v.end());
}
this code produces a string which still points to the double byte buffer and therefore this
results in a different hash value for the returned string as the value would be for the
basic_string<char> or C-String:
An example:
XalanDOMString str("Sint8");
std::string char_str(get_string(str));
Calling find in the multi-index results in a hash value 40.
Calling find in the multi-index for
const char* str="Sint8";
results in a hash value 13
The same result (13) can be achieved when calling on char_str.c_str(); c_str() cause the strings
internal buffer to be rebuild.
Since boost::hash is on the way to become a part of STL it should ensure to work with the
correctly intended copy of string. What is your opinion on this issue?
With Kind Regards,
Ovanes
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