I cut my teeth in some programming patterns, and I'm very new to this. I want to implement several CRTP classes containing an STL container. Let class A{}; serves as an example for a base class (compilation time), from which class B{}; and class C{}; are "derivatives" during compilation following the CRTP style.
Now both B and C will contain containers. For the purpose of the example, let it be std::vector and a std::set respectively. Now I want to expose iterators from them using the begin() and end() function, which provides an advanced iterator. However, I do not want to disclose what the exact container is that is inside B and C , and I want to define these functions for A , so that during the call, use the correct value for B and C
Is it possible? My current plan is to have an inner Iterator class for B as well as C , which will contain the actual iterator (vector or set, as appropriate) and delegate a call to it. However, this seems to be a lot of replicated glue code, and I suspect there is a better option.
I have a couple of questions:
How to declare internal clans in A , B and C so that it works well with CRTP. Does it need to be replicated for A , B and C ? Could it be an empty class in A , and I mask them in B and C with specialized implementations?
How can I set an iterator with less glue and less duplication?
I do not want to create dependencies with external libraries, for example boost, and I want to stick only to std. Therefore, I must implement everything that I need. Thanks for the help.
source share