title: Is it always safe to use std::vector<size_t> with different integer types?
body: <p>Trying to receive a vector with unknown big values I came up with a solution I thought to be entirely wrong: I supposed when an element of the <code>std::vector&lt;size_t&gt;</code> is assigned first to a small value and then to a big one there could be an error or data loss because the type for the entire vector was already set and some space in memory was arranged. </p>
  
  <p>However the following code works:</p>
  
  <pre><code>#include&lt;vector&gt;
  #include&lt;iostream&gt;
  #include&lt;typeinfo&gt;
  
  int main(){
  
      std::vector&lt;size_t&gt; vec;
  
      // Fixing size and adding small number which 
      // I suppose would set type as a small one, 
      // i.e. int 
      vec.resize(2);
      int i = 0;
      std::fill(vec.begin(),vec.end(),i);    
  
      // add a big number that should not fit smaller type
      unsigned long long bignum = 18446744073709551614;
      vec.push_back(bignum);
  
      std::cout&lt;&lt;vec[0]&lt;&lt;" "&lt;&lt;vec[1]&lt;&lt;" "&lt;&lt;vec[2]&lt;&lt;std::endl;
      std::cout&lt;&lt;typeid(vec[0]).name()&lt;&lt;std::endl
      &lt;&lt;typeid(vec[1]).name()&lt;&lt;std::endl&lt;&lt;typeid(vec[2]).name()&lt;&lt;std::endl;
  
      // cell 0 was already initialized with int, trying to make oveflow
      vec[0] = 18446744073709551613;
  
      std::cout&lt;&lt;vec[0]&lt;&lt;" "&lt;&lt;vec[1]&lt;&lt;" "&lt;&lt;vec[2]&lt;&lt;std::endl;
      std::cout&lt;&lt;typeid(vec[0]).name()&lt;&lt;std::endl
      &lt;&lt;typeid(vec[1]).name()&lt;&lt;std::endl&lt;&lt;typeid(vec[2]).name()&lt;&lt;std::endl;
  
      return 1;   
  }
  </code></pre>
  
  <p>However, the output does not contain type names, maybe because of my compiler:</p>
  
  <pre><code>$ ./a.out
  0 0 18446744073709551614
  m
  m
  m
  18446744073709551613 0 18446744073709551614
  m
  m
  m
  </code></pre>
  
  <p>So is it safe for all compilers and can I freely operate with <code>vector::&lt;size_t&gt;</code> (send to functions, etc) when I don't know the integer types used?</p>