Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It is not much clear, but I guess you want an automatic resize container (as javascript vectors) where lists indexes are 1 based (i.e. no list at address 0) and a method to insert at the end of one list at a given index. Basically something as this:</p> <pre><code>struct MyCollection: public std::vector&lt;std::list&lt;std::string&gt; &gt; { void push_at(size_t index, const std::string&amp; item) { resize(std::max(size(),index - 1); at(index - 1).push_back(item); } }; </code></pre> <p>Anything else you might want from such container is likely to be already implemented in the <code>vector</code> and <code>list</code> template classes (check stl documentation to see whats available), for example:</p> <pre><code>MyCollection a; //declares an empty collection a.push_at(6,"hello"); //create 6 lists and inserts "hello" at the end of the last one a[5]; //gets 6th list (method [] is 0-based on vector) a.push_at(6,"hi"); // since list already exists it just adds "hi" at the end a[5].front() //"hello" a[5].back() //"hi" </code></pre> <p>Other suggestions:</p> <ul> <li>if you plan to put a lot of items in there and do not need to have all lists object at consecutive addresses (i.e. compatibility of vector with C arrays), I suggest you use a <code>deque</code> instead of a <code>vector</code>, or provide a proper size hint with <code>reserve</code>, otherwise you might be find yourself wondering why sometimes adding a single string in a list that does not exists yet is so slow.</li> <li>STL uses 0-based indexes all around. You will only get confused by defining a 1-based one, so count your lists from 0 (just replace <code>index - 1</code> with <code>index</code> in the example above) and do your math on application logic)</li> </ul>
    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. This table or related slice is empty.
    1. 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