|
Boost Users : |
From: Giampiero Gabbiani (giampiero_gabbiani_at_[hidden])
Date: 2005-08-09 11:55:00
hi to all,
I'm trying to implementing a string class as a std::list of elements that
can be common char, wchar_t or something else (as utf-16 chars, for
example).
In order to obtain this, I've defined a collection as a template class, and
used with different value_type(s).
When I try to use the collection with char or wchar_t, the boost algo
to_upper works fine but, when I use the collection template with a
UTF16::Char (a class that implements the UTF-16 encoding) I obtain the
following exception:
Exception catch:St8bad_cast
The following code is the definition of the Char class and an example of its
use with the standard list and the boost algo:
namespace UTF16 {
class Char {
public:
Char();
Char(const char c);
// UTF-16 encoding constructor
Char(wchar_t v);
bool operator == (const Char& c) const;
bool operator != (const Char& c) const;
operator wchar_t () const;
Char(const Char& chr);
Char(Char& chr);
~Char();
Char& operator = (const Char& chr);
Char& operator = (Char& chr);
private:
u_int16_t* _value;
size_t _size;
};
}
int main(int argc, char *argv[]) {
try {
list<UTF16::Char> l;
l.push_back(UTF16::Char('a'));
// THE FOLLOWING LINE PRODUCES A 'bad_cast' exception...
boost::algorithm::to_upper(l);
} catch(const exception& error) {
cout << "Exception catch:" << error.what() << endl;
} catch(...) {
cerr << "Unhandled exception.\n";
}
return EXIT_SUCCESS;
}
Is there something wrong/missing in the definition of the Char class?
Or maybe the boost string algos are usable only with char and wchar_t?
Thanks in advance
Giampiero.
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