Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Access to the book is by no mean necessary.</p> <p>The issues we are dealing here are <em>Dependency</em> and <em>Reuse</em>.</p> <p>In a well-designed software, you try to isolate items from one another so as to reduce Dependencies, because Dependencies are a hurdle to overcome when change is necessary.</p> <p>In a well-designed software, you apply the <em>DRY</em> principle (Don't Repeat Yourself) because when a change is necessary, it's painful and error-prone to have to repeat it in a dozen different places.</p> <p>The "classic" OO mindset is increasingly bad at handling dependencies. By having lots and lots of methods depending directly on the internals of the class, the slightest change implies a whole rewrite. It need not be so.</p> <p>In C++, the STL (not the whole standard library), has been designed with the explicit goals of:</p> <ul> <li>cutting dependencies</li> <li>allowing reuse</li> </ul> <p>Therefore, the Containers expose well-defined interfaces that hide their internal representations but still offer sufficient access to the information they encapsulate so that Algorithms may be executed on them. All modifications are made through the container interface so that the invariants are guaranteed.</p> <p>For example, if you think about the requirements of the <code>sort</code> algorithm. For the implementation used (in general) by the STL, it requires (from the container):</p> <ul> <li>efficient access to an item at a given index: Random Access</li> <li>the ability to swap two items: not Associative</li> </ul> <p>Thus, any container that provides Random Access and is not Associative is (in theory) suitable to be sorted efficiently by (say) a Quick Sort algorithm.</p> <p>What are the Containers in C++ that satisfy this ?</p> <ul> <li>the basic C-array</li> <li><code>deque</code></li> <li><code>vector</code></li> </ul> <p>And any container that <em>you</em> may write if you pay attention to these details.</p> <p>It would be wasteful, wouldn't it, to rewrite (copy/paste/tweak) <code>sort</code> for each of those ?</p> <p>Note, for example, that there is a <code>std::list::sort</code> method. Why ? Because <code>std::list</code> does not offer random access (informally <code>myList[4]</code> does not work), thus the <code>sort</code> from algorithm is not suitable.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload