Subject: [Boost-bugs] [Boost C++ Libraries] #2548: Let's fix the logical constness of value_initialized!
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2008-11-28 19:26:10
#2548: Let's fix the logical constness of value_initialized!
--------------------------+-------------------------------------------------
Reporter: niels_dekker | Owner: fcacciola
Type: Bugs | Status: new
Milestone: Boost 1.38.0 | Component: utility
Version: Boost 1.37.0 | Severity: Problem
Keywords: |
--------------------------+-------------------------------------------------
The data() member function and the conversion operator of
boost::value_initialized<T> break the logical constness: both functions
are declared "const", while they return a non-const reference to the T
object that is owned by value_initialized<T>. I think both of them should
be replaced by a pair of overloaded functions for const and non-const
access.
I don't think that there ever was a good reason for the data() function to
break the logical constness. But clearly, there ''was'' a reason for the
conversion operator to do so, at the time value_initialized was first
released, in 2002. At that time, some commonly used compilers would
complain about ambiguity when the conversion operator would be overloaded
for const and non-const, in some specific use cases. As described at
http://www.boost.org/doc/libs/1_37_0/libs/utility/value_init.htm#val_init
In January 2004, "deep const semantics" still wasn't feasible, apparently
due to compiler errors in VC++ and Borland:
''[boost] value_initialized, deep const, and template instantiation''
http://lists.boost.org/Archives/boost/2004/01/59987.php
http://lists.boost.org/Archives/boost/2004/01/60020.php
Nowadays I think that things have changed for the better. I just replaced
the single conversion operator by overloads for const and non-const in my
local copy, and tested for VC++ 2003 (7.1), VC++ 2008 (9.0), and !CodeGear
2009 (6.10). And all of them passed the tests!
Therefore I'd like to propose fixing the issue, according to the attached
patch. Fernando, shall we give it a try?
I'm aware that the proposed fix potentially breaks some user code, but I
think that those cases are easily fixed, and I think that most Boost users
are likely to appreciate logical constness.
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/2548> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:49:59 UTC