Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Why do you need your interface to be container-independent? Scott Meyers in his "Effective STL" gives a good reasoning for <em>not</em> trying to make your code container-independent, no matter how strong the temptation is. Basically, containers are intended for completely different usage: you probably don't want to store your output in map or set (they're not interval containers), so you're left with vector, list and deque, and why do you wish to have vector where you need list and vice versa? They're completely different, and you'll have better results using all the features of one of them than trying to make both work. Well, just consider reading "Effective STL": it's worth your time.</p> <p>If you know something about your container, though, you may consider doing something like</p> <pre><code> template void get_sequence(T_Container & container) { //... container.assign(iter1, iter2); //... } </code></pre> <p>or maybe</p> <pre><code> template void get_sequence(T_Container & container) { //... container.resize(size); //use push_back or whatever //... } </code></pre> <p>or even control what you do with a strategy, like</p> <pre><code> class AssignStrategy // for stl { public: template void fill(T_Container & container, T_Container::iterator it1, T_Container::iterator it2){ container.assign(it1, it2); } }; class ReserveStrategy // for vectors and stuff { public: template void fill(T_Container & container, T_Container::iterator it1, T_Container::iterator it2){ container.reserve(it2 - it1); while(it1 != it2) container.push_back(*it1++); } }; template void get_sequence(T_Container & container) { //... T_FillStrategy::fill(container, iter1, iter2); //... } </code></pre>
 

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