mirror of
https://github.com/boostorg/ptr_container.git
synced 2026-02-27 05:12:11 +00:00
*** empty log message ***
[SVN r33671]
This commit is contained in:
@@ -290,6 +290,8 @@ ul.auto-toc {
|
||||
<div class="document" id="boost-pointer-container-library">
|
||||
<h1 class="title"><img alt="Boost" src="boost.png" /> Pointer Container Library</h1>
|
||||
<h2 class="subtitle" id="usage-guidelines">Usage Guidelines</h2>
|
||||
<div class="section">
|
||||
<h1><a id="choosing-the-right-container" name="choosing-the-right-container">Choosing the right container</a></h1>
|
||||
<p>The recommended usage pattern of the container classes are the same as the
|
||||
for normal standard containers.</p>
|
||||
<p><tt class="docutils literal"><span class="pre">ptr_vector</span></tt>, <tt class="docutils literal"><span class="pre">ptr_list</span></tt> and <tt class="docutils literal"><span class="pre">ptr_deque</span></tt> offer the programmer different
|
||||
@@ -306,6 +308,60 @@ one element for each key. Otherwise, it supports equivalent keys.
|
||||
<tt class="docutils literal"><span class="pre">ptr_set</span></tt> and <tt class="docutils literal"><span class="pre">ptr_map</span></tt> support unique keys.
|
||||
<tt class="docutils literal"><span class="pre">ptr_multiset</span></tt> and <tt class="docutils literal"><span class="pre">ptr_multimap</span></tt>
|
||||
support equivalent keys.</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="recommended-practice-for-object-oriented-programming" name="recommended-practice-for-object-oriented-programming">Recommended practice for Object-Oriented Programming</a></h1>
|
||||
<p>Idiomtic Object-Oriented Programming in C++ looks a bit different from
|
||||
the way it is done in other languages. This is partly because C++
|
||||
has both value and reference semantics, and partly because C++ is more flexible
|
||||
than other languages. Below is a list of recommendations that you are
|
||||
encouraged to follow:</p>
|
||||
<div class="section">
|
||||
<h2><a id="make-base-classes-abstract-and-without-data" name="make-base-classes-abstract-and-without-data">1. Make base classes abstract and without data</a></h2>
|
||||
<p>The has the following advantages:</p>
|
||||
<blockquote>
|
||||
<ol class="loweralpha simple">
|
||||
<li>It reduces <em>coupling</em> because you do not have to maintain or update state</li>
|
||||
</ol>
|
||||
<!-- -->
|
||||
<ol class="loweralpha simple" start="2">
|
||||
<li>It helps you to avoid <em>slicing</em></li>
|
||||
</ol>
|
||||
<!-- -->
|
||||
<ol class="loweralpha simple" start="3">
|
||||
<li>It ensures you <em>override</em> the right function</li>
|
||||
</ol>
|
||||
</blockquote>
|
||||
<p>You might also want to read the following articles:</p>
|
||||
<ul class="simple">
|
||||
<li>Kevlin Henney's <a class="reference" href="http://www.two-sdg.demon.co.uk/curbralan/papers/SixOfTheBest.pdf">Six of the best</a></li>
|
||||
</ul>
|
||||
<ul class="simple">
|
||||
<li>Jack Reeves' <a class="reference" href="http://www.ddj.com/documents/s=10011/q=1/cuj0602reeves/0602reeves.html">Multiple Inheritance Considered Useful</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h2><a id="make-virtual-functions-private-and-provide-a-non-virtual-public-forwarding-function" name="make-virtual-functions-private-and-provide-a-non-virtual-public-forwarding-function">2. Make virtual functions private and provide a non-virtual public forwarding function</a></h2>
|
||||
<p>This has the following advantages:</p>
|
||||
<blockquote>
|
||||
<ol class="loweralpha simple">
|
||||
<li>It makes sure all calls to the virtual function always goes through one place in your code</li>
|
||||
</ol>
|
||||
<!-- -->
|
||||
<ol class="loweralpha simple" start="2">
|
||||
<li>It enables you to check preconditions and postconditions inside the forwarding function</li>
|
||||
</ol>
|
||||
</blockquote>
|
||||
<p>You might also want to read Herb Sutter's article <a class="reference" href="http://www.gotw.ca/publications/mill18.htm">Virtuality</a>.</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h2><a id="derive-your-base-class-from-boost-noncopyable" name="derive-your-base-class-from-boost-noncopyable">3. Derive your base class from <tt class="docutils literal"><span class="pre">boost::noncopyable</span></tt></a></h2>
|
||||
<p>Having an abstact base class prevents slicing when the base class is involved, but
|
||||
it does not prevent it for classes further down the hierarchy. This is where
|
||||
<a class="reference" href="http://www.boost.org/libs/utility/utility.htm#Class_noncopyable">boost::noncopyable</a> is handy to use.</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h2><a id="don-t-allow-nulls-if-you-can-avoid-it-null-object" name="don-t-allow-nulls-if-you-can-avoid-it-null-object">4. don't allow nulls if you can avoid it, Null Object</a></h2>
|
||||
<p><strong>Navigate:</strong></p>
|
||||
<ul class="simple">
|
||||
<li><a class="reference" href="ptr_container.html">home</a></li>
|
||||
@@ -320,5 +376,7 @@ support equivalent keys.</p>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
Usage Guidelines
|
||||
================
|
||||
|
||||
Choosing the right container
|
||||
----------------------------
|
||||
|
||||
The recommended usage pattern of the container classes are the same as the
|
||||
for normal standard containers.
|
||||
|
||||
@@ -27,6 +30,71 @@ one element for each key. Otherwise, it supports equivalent keys.
|
||||
``ptr_multiset`` and ``ptr_multimap``
|
||||
support equivalent keys.
|
||||
|
||||
Recommended practice for Object-Oriented Programming
|
||||
----------------------------------------------------
|
||||
|
||||
Idiomtic Object-Oriented Programming in C++ looks a bit different from
|
||||
the way it is done in other languages. This is partly because C++
|
||||
has both value and reference semantics, and partly because C++ is more flexible
|
||||
than other languages. Below is a list of recommendations that you are
|
||||
encouraged to follow:
|
||||
|
||||
1. Make base classes abstract and without data
|
||||
++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
The has the following advantages:
|
||||
|
||||
a. It reduces *coupling* because you do not have to maintain or update state
|
||||
|
||||
..
|
||||
|
||||
b. It helps you to avoid *slicing*
|
||||
|
||||
..
|
||||
|
||||
c. It ensures you *override* the right function
|
||||
|
||||
You might also want to read the following articles:
|
||||
|
||||
- Kevlin Henney's `Six of the best`__
|
||||
|
||||
.. __: http://www.two-sdg.demon.co.uk/curbralan/papers/SixOfTheBest.pdf
|
||||
|
||||
- Jack Reeves' `Multiple Inheritance Considered Useful`__
|
||||
|
||||
.. __: http://www.ddj.com/documents/s=10011/q=1/cuj0602reeves/0602reeves.html
|
||||
|
||||
|
||||
2. Make virtual functions private and provide a non-virtual public forwarding function
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
This has the following advantages:
|
||||
|
||||
a. It makes sure all calls to the virtual function always goes through one place in your code
|
||||
|
||||
..
|
||||
|
||||
b. It enables you to check preconditions and postconditions inside the forwarding function
|
||||
|
||||
You might also want to read Herb Sutter's article `Virtuality`__.
|
||||
|
||||
.. __: http://www.gotw.ca/publications/mill18.htm
|
||||
|
||||
3. Derive your base class from ``boost::noncopyable``
|
||||
+++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
Having an abstact base class prevents slicing when the base class is involved, but
|
||||
it does not prevent it for classes further down the hierarchy. This is where
|
||||
`boost::noncopyable`__ is handy to use.
|
||||
|
||||
.. __ : http://www.boost.org/libs/utility/utility.htm#Class_noncopyable
|
||||
|
||||
|
||||
|
||||
4. don't allow nulls if you can avoid it, Null Object
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
|
||||
**Navigate:**
|
||||
|
||||
- `home <ptr_container.html>`_
|
||||
|
||||
@@ -333,7 +333,6 @@ the <a class="reference" href="reference.html#the-clone-allocator-concept">Clone
|
||||
<h1><a id="the-clonable-concept" name="the-clonable-concept">The Clonable concept</a></h1>
|
||||
<p><strong>Refinement of</strong></p>
|
||||
<ul class="simple">
|
||||
<li>Copy Constructible</li>
|
||||
<li>Heap Allocable</li>
|
||||
<li>Heap Deallocable</li>
|
||||
</ul>
|
||||
@@ -365,22 +364,26 @@ the containers does not even require the stored type to be Clonable.</p>
|
||||
<p><strong>Valid expressions</strong></p>
|
||||
<table border="1" class="docutils">
|
||||
<colgroup>
|
||||
<col width="24%" />
|
||||
<col width="18%" />
|
||||
<col width="58%" />
|
||||
<col width="19%" />
|
||||
<col width="14%" />
|
||||
<col width="46%" />
|
||||
<col width="20%" />
|
||||
</colgroup>
|
||||
<tbody valign="top">
|
||||
<tr><td><strong>Expression</strong></td>
|
||||
<td><strong>Type</strong></td>
|
||||
<td><strong>Semantics</strong></td>
|
||||
<td><strong>Postcondition</strong></td>
|
||||
</tr>
|
||||
<tr><td><tt class="docutils literal"><span class="pre">new_clone(a);</span></tt></td>
|
||||
<td><tt class="docutils literal"><span class="pre">T*</span></tt></td>
|
||||
<td>Allocate a new object that can be considered equivalent to the <tt class="docutils literal"><span class="pre">a</span></tt> object</td>
|
||||
<td><tt class="docutils literal"><span class="pre">typeid(new_clone(a))</span> <span class="pre">==</span> <span class="pre">typeid(a)</span></tt></td>
|
||||
</tr>
|
||||
<tr><td><tt class="docutils literal"><span class="pre">delete_clone(ptr);</span></tt></td>
|
||||
<td><tt class="docutils literal"><span class="pre">void</span></tt></td>
|
||||
<td>Deallocate an object previously allocated with <tt class="docutils literal"><span class="pre">allocate_clone()</span></tt>. Must not throw</td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@@ -52,7 +52,6 @@ The Clonable concept
|
||||
|
||||
**Refinement of**
|
||||
|
||||
- Copy Constructible
|
||||
- Heap Allocable
|
||||
- Heap Deallocable
|
||||
|
||||
@@ -70,11 +69,11 @@ the containers does not even require the stored type to be Clonable.
|
||||
|
||||
**Valid expressions**
|
||||
|
||||
===================================== =========================== ========================================================================================
|
||||
**Expression** **Type** **Semantics**
|
||||
``new_clone(a);`` ``T*`` Allocate a new object that can be considered equivalent to the ``a`` object
|
||||
===================================== =========================== ======================================================================================== ===================================
|
||||
**Expression** **Type** **Semantics** **Postcondition**
|
||||
``new_clone(a);`` ``T*`` Allocate a new object that can be considered equivalent to the ``a`` object ``typeid(new_clone(a)) == typeid(a)``
|
||||
``delete_clone(ptr);`` ``void`` Deallocate an object previously allocated with ``allocate_clone()``. Must not throw
|
||||
===================================== =========================== ========================================================================================
|
||||
===================================== =========================== ======================================================================================== ===================================
|
||||
|
||||
|
||||
Default implementation
|
||||
|
||||
Reference in New Issue
Block a user