← Back to team overview

dolfin team mailing list archive

Ugly const_cast?

 

As some might have seen from the buildbot's failures last night, we're
currently implementing a nested stack based xml parser that enables
the reuse of the different parsers (we call them XMLHandlers) when
reading and writing data to xml files. We want to use the handlers for
both input and output, and we run into problems at construction time.
For instance, when writing a std::vector<uint, int> x to file, we get
a const reference, and need to cast away the constness in order to
construct the XMLArray object:


void NewXMLFile::operator<<(const std::vector<int>& x)
{
  XMLArray xml_array(const_cast<std::vector<int>&>(x), *this);
  xml_array.write(filename);
}

Does anyone object to this const_cast?

Btw, we should probably not send the filename here, but the ofstream
being written to, in order to reuse the output methods as well as the
parsing methods.
-- 
Ola Skavhaug


Follow ups