[utility] initialized_value - a convenience class for value_init.hpp

For the convenience of the end users, I would like to add a little class to value_init.hpp, called initialized_value, having a conversion operator as its one and only member. Because it's just an extra feature of value_init, and Fernando Cacciola (the owner of value_init) already agrees that this class is a useful addition, I don't think an officially review of the class is necessary. But please tell me if you think otherwise. Details: The following syntax should initialize an object in a generic way, assuming that its type T is CopyConstructible: T obj1 = T(); Unfortunately this object may *not* be initialized properly, because of value-initialization related compiler issues of various C++ implementations, including MSVC, Borland, and GCC. (Boost ticket #1217, #1459, and #1491.) Fernando Cacciola and I have recently reimplemented boost::value_initialized, to work around those issues. (value_init.hpp, release branch, changeset [42501].) So the next release version of boost::value_initialized can be used to properly initialize an object, even in the presence of those compiler issues, as follows: T obj2 = get( value_initialized<T>() ); Still this way of initializing an object is rather verbose, and it has a form of code duplication, because it mentions the type of the object (T) twice. Within user code, the type may of course look more like Namespace::Template<Arg>::Type. Therefore I would like to add a class, boost::initialized_value, supporting the following: T obj3 = initialized_value(); The class would be implemented as follows: namespace boost { class initialized_value { public : template <class T> operator T() const { return get( value_initialized<T>() ); } }; } Its conversion operator would provide an appropriate value-initialized object for any CopyConstructible type T. Any comments are welcome. If it's okay, I would like to add it to the trunk version of value_init.hpp, next week. Kind regards, -- Niels Dekker http://www.xs4all.nl/~nd/dekkerware Scientific programmer at LKEB, Leiden University Medical Center

On Monday 7 January I wrote:
For the convenience of the end users, I would like to add a little class to value_init.hpp, called initialized_value, having a conversion operator as its one and only member.
I just did so, as discussed with Fernando Cacciola, the owner of value_init.hpp. Please take a look the trunk: http://svn.boost.org/svn/boost/trunk/boost/utility/value_init.hpp http://svn.boost.org/svn/boost/trunk/libs/utility/value_init.htm Changesets: http://svn.boost.org/trac/boost/changeset/42815 http://svn.boost.org/trac/boost/changeset/42816 Any comments are welcome. I hope to have it included with the upcoming Boost release, but I'm not sure if it's still in time, especially because I need to wait for the regression tests... Next week I hope to merge it to the release branch... Kind regards, -- Niels Dekker http://www.xs4all.nl/~nd/dekkerware Scientific programmer at LKEB, Leiden University Medical Center
participants (1)
-
Niels Dekker - mail address until 2008-12-31