From 79bbf71d0d9ef537659b79d732634b0001a0545b Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Mon, 14 Jan 2008 21:46:20 +0000 Subject: [PATCH] Minor "beautifications" of value_init documentation, inc. placing references in order of appearance [SVN r42779] --- value_init.htm | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/value_init.htm b/value_init.htm index 7cf9e9b..578eed3 100644 --- a/value_init.htm +++ b/value_init.htm @@ -32,7 +32,7 @@ Acknowledgements
@@ -46,7 +46,7 @@ for initialization. Depending on the type, the value of a newly constructed object can be zero-initialized (logically 0), default-constructed (using the default constructor), or indeterminate. When writing generic code, -this problem must be addressed. value_initialized provides +this problem must be addressed. The template value_initialized provides a solution with consistent syntax for value initialization of scalar, union and class types. Moreover, value_initialized offers a workaround to various @@ -84,7 +84,7 @@ initialized that way). The third form, T3 var3 = {} initializes an aggregate, typically a "C-style" struct or a "C-style" array. However, the syntax is not allowed for a class that has an explicitly declared constructor. (But watch out for an upcoming C++ language change, -by Bjarne Stroustrup et al [3]!) +by Bjarne Stroustrup et al [1]!) The fourth form is the most generic form of them, as it can be used to initialize arithmetic types, class types, aggregates, pointers, and other types. The declaration, T4 var4 = T4(), should be read @@ -98,7 +98,7 @@ be optimized away, C++ still requires the type T4 to be A class may not be CopyConstructible, for example because it may have a private and undefined copy constructor, or because it may be derived from boost::noncopyable. -Scott Meyers [4] explains why a class would be defined like that. +Scott Meyers [2] explains why a class would be defined like that.

There is another, less obvious disadvantage to the fourth form, T4 var4 = T4(): @@ -120,11 +120,11 @@ constructed by the following declaration:

Details

-

The C++ standard [1] contains the definitions +

The C++ standard [3] contains the definitions of zero-initialization and default-initialization. Informally, zero-initialization means that the object is given the initial value 0 (converted to the type) and default-initialization means that - POD [2] types are zero-initialized, while non-POD class + POD [4] types are zero-initialized, while non-POD class types are initialized with their corresponding default constructors. A declaration can contain an initializer, which specifies the object's initial value. The initializer can be just '()', which states that @@ -225,7 +225,7 @@ GCC Bug 33916 - Default constructor fails to initialize array members
Borland Report 51854 - Value-initialization: POD struct should be zero-initialized -
Reported by Niels Dekker (LKEB, Leiden University Medical Center), 2007-11-09 +
Reported by Niels Dekker (LKEB, Leiden University Medical Center), 2007-09-11

@@ -299,23 +299,23 @@ the wrapped object is always performed with the get() idiom:

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

References

- [1] The C++ Standard, Second edition (2003), ISO/IEC 14882:2003
- [2] POD stands for "Plain Old Data"
- [3] Bjarne Stroustrup, Gabriel Dos Reis, and J. Stephen Adamczyk wrote + [1] Bjarne Stroustrup, Gabriel Dos Reis, and J. Stephen Adamczyk wrote various papers, proposing to extend the support for brace-enclosed initializer lists in the next version of C++. This would allow a variable var of any DefaultConstructible type T to be value-initialized by doing T var = {}. The papers are listed at Bjarne's web page, My C++ Standards committee papers
- [4] Scott Meyers, Effective C++, Third Edition, item 6, + [2] Scott Meyers, Effective C++, Third Edition, item 6, Explicitly disallow the use of compiler-generated functions you do not want, - Scott Meyers: Books and CDs + Scott Meyers: Books and CDs
+ [3] The C++ Standard, Second edition (2003), ISO/IEC 14882:2003
+ [4] POD stands for "Plain Old Data"

Acknowledgements

value_initialized was developed by Fernando Cacciola, with help and suggestions from David Abrahams and Darin Adler.
-Special thanks to Björn Karlsson who carefully edited and completed this documentation. +Special thanks to Björn Karlsson who carefully edited and completed this documentation.

value_initialized was reimplemented by Fernando Cacciola and Niels Dekker for Boost release version 1.35 (2008), offering a workaround to various compiler issues.