title: add to vector without copying struct data
body: <p>This is presumable a simple C++ question, but I'm relearning C++ and don't know some of the basics.  I have a class that includes a struct with a vector of objects in it, so something like this:</p>
  
  <pre><code>struct my_struct{
      Irrelevant_Object object,
      vector&lt;tuple&gt; tuple_list;
  }
  </code></pre>
  
  <p>The struct and the tuple (another struct) are predefined by the architecture and given to me in my method; so I can't change them.  I want to generate and insert a tuple into the originaly empty tuple_list.  </p>
  
  <p>The simple solution is have a method which allocates a new tuple object, fills in the tuple data, then call tuple_list.push_back() and pass in the allocated tuple.  But this would require allocating a new tuple only to have the push_back method copy all of the contents of the (large) tuple struct into an already defined memory space of the vector.  So I'm paying the expense of an allocation/delete as well as the lesser expense of copying the tuple contents into the vector to do it this way. It seems rather inefficent, and since this method would be in the critical path of the function I would prefer something faster (admitedly I doubt this method would be the bottle-neck, and I know early optimization == bad. However, I'm asking this question more to learn something about C++ syntax then out of a deperate need to actually do this in my code).</p>
  
  <p>So my question is, is there a quicker way to fill the contents of my tuple list without allocating and copying a tuple?  If this was an array I could make the array as large as I want, then past a reference to tuple_list[0] to the function that creates the tuple.  That way the funciton could fill the empty contents of the already allocated tuple within the array without allocating a new one or copying from one tuple to another. I tried to do that with the vector out of curiousity and ended up with a seg fault when my itterator pointed to 0x0, so I assume that syntax doesn't work for vectors.  So is there a quick way of doing this assignment?</p>
  
  <p>Since this is a question as much to learn the language as for actual use feel free to throw in any other tangentally relevant stuff you think are interesting, I'm looking to learn.</p>
  
  <p>Thanks.</p>