Note that there are some explanatory texts on larger screens.

plurals
  1. POCRTP'ed Containers
    primarykey
    data
    text
    <p>I am cutting my teeth at some template programming and I am very new to this. What I want to implement are a few CRTP classes that contain an STL container. Let <code>class A{};</code> serve as an example for the (compile time) base class from which <code>class B{};</code> and <code>class C{};</code> are "derived" at compile time following the CRTP style.</p> <p>Now both <code>B</code> and <code>C</code> will contain containers. For the purpose of the example let it be a <code>std::vector</code> and a <code>std::set</code> respectively. Now, I want to expose the iterators of these via a <code>begin()</code> and an <code>end()</code> function that exposes a forward iterator. However, I do not want to expose what is the exact container that is inside <code>B</code> and <code>C</code> and I want to define these functions for <code>A</code>, so that at call time the correct one for <code>B</code> and <code>C</code> get used.</p> <p>Is this possible ? Right now my plan is to have a <code>Iterator</code> inner class for <code>B</code> as well as <code>C</code> that will contain the actual iterator of (a vector or a set as the case may be) and delegate the call to it. However this seems to be a lot of replicated glue code and I suspect there is a better option.</p> <p>I have a couple of questions: </p> <ol> <li><p>How do I declare the inner clases in <code>A</code>, <code>B</code> and <code>C</code> so that it plays well with CRTP. Do I need to replicate it for <code>A</code>, <code>B</code> and <code>C</code> ? Can it be an empty class in <code>A</code> and I mask them in <code>B</code> and <code>C</code> with specialized implementations ?</p></li> <li><p>How can I expose the iterator with less glue and less duplication ?</p></li> </ol> <p>I do not want to create dependencies with external libraries like boost and want to stick to std only. So I have to implement whatever extra I need myself. Thanks for all the help.</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.
 

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