Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The STL has two associative containers: <code>std::map&lt;K,V&gt; and</code>std::multimap. There is also <code>std::set&lt;V&gt;</code> which should be an adaptor of <code>std::map&lt;V,void&gt;</code>, but as such it isn't an associative container. The multimap is similar to the map, only it allows multiple identical keys within the same container. Both map and multimap hold elements of type <code>std::pair&lt;K,V&gt;</code>. In other words, <code>std::map&lt;K,V&gt;::value_type == std::pair&lt;K,V&gt;</code>, but <code>std::map&lt;K,V&gt;::key_type == K</code> and <code>std::map&lt;K,V&gt;::mapped_type == V</code>.</p> <p>As for "Type", I am not entirely sure what you mean. If you mean parameterized classes then C++ calls this "Template Programming", or "Generic Programming". In the above, <code>std::map&lt;K,V&gt;</code> is parameterized over K and V for the keys' type and the values' type. C++ also supports template functions:</p> <pre><code>template&lt;typename T&gt; void f(T o); </code></pre> <p>will declare a function that takes as a parameter any type at all, including primitive types. C++ doesn't support generic type resolution, such that the type T must of certain hierarchy. For now, all you can do is just assume the passed type is indeed of the correct hierarchy, and the compiler will complain if you try to call a non-declared function over an object of that type.</p> <pre><code>template&lt;typename T&gt; void f(T o) { o.do_it(); } </code></pre> <p>The above will work as long as T defines the method <code>do_it()</code>.</p>
 

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