[utility] A fix for the const issue of value_initialized

The boost::value_initialized<T> utility has a major issue regarding const-correctness: It has a const-qualified conversion operator, returning a non-const reference to the T object it owns. I have already created a ticket, <https://svn.boost.org/trac/boost/ticket/2548>, and mailed Fernando Cacciola (the author of value_initialized) on this issue. He agrees that it should be fixed, and he allows me to do so. The patch I've attached to the ticked replaces the current conversion operator by two of them, overloaded for const and non-const access: operator T const &() const { return this->data(); } operator T&() { return this->data(); } The patch also fixes value_initialized::data() in a similar way. Please let me know if you have any problem with the patch. Otherwise I'd like to apply it to the trunk by the end of the week: https://svn.boost.org/trac/boost/attachment/ticket/2548/value_initialized_co... Note that the issue has been discussed here already five years ago: http://lists.boost.org/Archives/boost/2004/01/59987.php At that time, some non-conforming compilers couldn't deal with conversion operators overloaded for const and non-const access. But now I've tested the value_initialized patch on a few compilers (MSVC 2003, MSVC 2008, CodeGear), and they all succeeded. After the commit, I'll keep a close look at the regression page, of course. Kind regards, Niels -- Niels Dekker http://www.xs4all.nl/~nd/dekkerware Scientific programmer at LKEB, Leiden University Medical Center

The boost::value_initialized<T> utility has a major issue regarding const-correctness: It has a const-qualified conversion operator, returning a non-const reference to the T object it owns. I have already created a ticket, <https://svn.boost.org/trac/boost/ticket/2548>, and mailed Fernando Cacciola (the author of value_initialized) on this issue. He agrees that it should be fixed, and he allows me to do so. The patch I've attached to the ticked replaces the current conversion operator by two of them, overloaded for const and non-const access
Just committed to the trunk: https://svn.boost.org/trac/boost/changeset/51355 https://svn.boost.org/trac/boost/changeset/51356 Please let me know if the commits might cause any troubles. I'll keep a look at the regression page, http://www.boost.org/development/tests/trunk/developer/utility_.html Kind regards, Niels -- Niels Dekker http://www.xs4all.nl/~nd/dekkerware Scientific programmer at LKEB, Leiden University Medical Center
participants (1)
-
Niels Dekker - mail address until 2010-10-10