Index: value_init.htm =================================================================== --- value_init.htm (revision 61724) +++ value_init.htm (working copy) @@ -33,6 +33,7 @@
@@ -123,6 +124,12 @@
+The template initialized
+offers both value-initialization and direct-initialization.
+It is especially useful as a data member type, allowing the very same object
+to be either direct-initialized or value-initialized.
+
The const
object initialized_value
allows value-initializing a variable as follows:
@@ -340,6 +347,52 @@value_initialized<int> x ;+
get(x) = 1 ; // OK
value_initialized<int const> cx ;
get(x) = 1 ; // ERROR: Cannot modify a const object
value_initialized<int> const x_c ;
get(x_c) = 1 ; // ERROR: Cannot modify a const object
value_initialized<int const> const cx_c ;
get(cx_c) = 1 ; // ERROR: Cannot modify a const object+ +
template class initialized<T>
namespace boost {+ +The template class
template<class T>
class initialized
{ +
public : +
initialized() : x() {} +
explicit initialized(T const & arg) : x(arg) {} +
operator T const &() const; +
operator T&(); +
T const &data() const; +
T& data(); +
void swap( value_initialized<T>& ); +
+
private : +
unspecified x ; +
} ; +
+
template<class T> +
T const& get ( initialized<T> const& x ); +
+
template<class T> +
T& get ( initialized<T>& x ); +
+
} // namespace boost +boost::initialized<T>
supports both value-initialization +and direct-initialization, so its interface is a superset of the interface +ofvalue_initialized<T>
: Its default-constructor +value-initializes the wrapped object just like the default-constructor of +value_initialized<T>
, butboost::initialized<T>
+also offers an extraexplicit
+constructor, which direct-initializes the wrapped object by the specified value. ++ +
+ +initialized<T>
is especially useful when the wrapped +object must be either value-initialized or direct-initialized, depending on +runtime conditions. For example,initialized<T>
could +hold the value of a data member that may be value-initialized by some +constructors, and direct-initialized by others. +On the other hand, if it is known beforehand that the +object must always be value-initialized,value_initialized<T>
+may be preferable. And if the object must always be +direct-initialized, none of the two wrappers really needs to be used. +
initialized_value
@@ -399,6 +452,9 @@value_initialized was reimplemented by Fernando Cacciola and Niels Dekker for Boost release version 1.35 (2008), offering a workaround to various compiler issues.
+
boost::initialized
was very much inspired by feedback from Edward Diener and + Jeffrey Hellrung. +initialized_value was written by Niels Dekker, and added to Boost release version 1.36 (2008).
Developed by Fernando Cacciola, @@ -407,9 +463,9 @@
-Revised 03 October 2009
+Revised 1 May 2010
-© Copyright Fernando Cacciola, 2002, 2009.
+© Copyright Fernando Cacciola, 2002 - 2010.
Distributed under the Boost Software License, Version 1.0. See www.boost.org/LICENSE_1_0.txt