Ticket #3472: initialized_documentation.patch
File initialized_documentation.patch, 4.3 KB (added by , 12 years ago) |
---|
-
value_init.htm
33 33 34 34 <ul> 35 35 <li><a href="#val_init"><code>template class value_initialized<T></code></a></li> 36 <li><a href="#initialized"><code>template class initialized<T></code></a></li> 36 37 <li><a href="#initialized_value"><code>initialized_value</code></a></li> 37 38 38 39 </ul> … … 123 124 </pre> 124 125 </p> 125 126 <p> 127 The template <a href="#initialized"><code>initialized</code></a> 128 offers both value-initialization and direct-initialization. 129 It is especially useful as a data member type, allowing the very same object 130 to be either direct-initialized or value-initialized. 131 </p> 132 <p> 126 133 The <code>const</code> object <a href="#initialized_value"><code>initialized_value</code></a> 127 134 allows value-initializing a variable as follows: 128 135 <pre> … … 340 347 341 348 <pre>value_initialized<int> x ;<br>get(x) = 1 ; // OK<br><br>value_initialized<int const> cx ;<br>get(x) = 1 ; // ERROR: Cannot modify a const object<br><br>value_initialized<int> const x_c ;<br>get(x_c) = 1 ; // ERROR: Cannot modify a const object<br><br>value_initialized<int const> const cx_c ;<br>get(cx_c) = 1 ; // ERROR: Cannot modify a const object<br></pre> 342 349 350 <h2><a name="initialized"><code>template class initialized<T></code></a></h2> 351 352 <pre>namespace boost {<br><br>template<class T><br>class initialized<br>{ 353 <br> public : 354 <br> initialized() : x() {} 355 <br> explicit initialized(T const & arg) : x(arg) {} 356 <br> operator T const &() const; 357 <br> operator T&(); 358 <br> T const &data() const; 359 <br> T& data(); 360 <br> void swap( value_initialized<T>& ); 361 <br> 362 <br> private : 363 <br> <i>unspecified</i> x ; 364 <br>} ; 365 <br> 366 <br>template<class T> 367 <br>T const& get ( initialized<T> const& x ); 368 <br> 369 <br>template<class T> 370 <br>T& get ( initialized<T>& x ); 371 <br> 372 <br>} // namespace boost 373 <br></pre> 374 375 The template class <code>boost::initialized<T></code> supports both value-initialization 376 and direct-initialization, so its interface is a superset of the interface 377 of <code>value_initialized<T></code>: Its default-constructor 378 value-initializes the wrapped object just like the default-constructor of 379 <code>value_initialized<T></code>, but <code>boost::initialized<T></code> 380 also offers an extra <code>explicit</code> 381 constructor, which direct-initializes the wrapped object by the specified value. 382 <p> 383 384 <code>initialized<T></code> is especially useful when the wrapped 385 object must be either value-initialized or direct-initialized, depending on 386 runtime conditions. For example, <code>initialized<T></code> could 387 hold the value of a data member that may be value-initialized by some 388 constructors, and direct-initialized by others. 389 On the other hand, if it is known beforehand that the 390 object must <i>always</i> be value-initialized, <code>value_initialized<T></code> 391 may be preferable. And if the object must always be 392 direct-initialized, none of the two wrappers really needs to be used. 393 </p> 394 395 343 396 <h2><a name="initialized_value"><code>initialized_value</code></a></h2> 344 397 345 398 <pre> … … 399 452 <p>value_initialized was reimplemented by Fernando Cacciola and Niels Dekker 400 453 for Boost release version 1.35 (2008), offering a workaround to various compiler issues. 401 454 </p> 455 <p><code>boost::initialized</code> was very much inspired by feedback from Edward Diener and 456 Jeffrey Hellrung. 457 </p> 402 458 <p>initialized_value was written by Niels Dekker, and added to Boost release version 1.36 (2008). 403 459 </p> 404 460 <p>Developed by <a href="mailto:fernando_cacciola@hotmail.com">Fernando Cacciola</a>, … … 407 463 </p> 408 464 409 465 <hr> 410 <p>Revised 03 October 2009</p>466 <p>Revised 1 May 2010</p> 411 467 412 <p>© Copyright Fernando Cacciola, 2002 , 2009.</p>468 <p>© Copyright Fernando Cacciola, 2002 - 2010.</p> 413 469 414 470 <p>Distributed under the Boost Software License, Version 1.0. See 415 471 <a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a></p>