title: Initializer list vs. vector
body: <p>In C++11, one can use initializer lists to initialize parameters in functions. What is the purpose of it? Can't the same be done with const vectors? What is the difference of the two programs below?</p>
  
  <p>Using an initializer list:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  int sumL(initializer_list&lt;int&gt; l){
      int sum = 0;
      for (const auto i: l){
          sum += i;
      }
      return sum;
  }
  
  int main(){
  
      cout &lt;&lt; sumL({1, 2, 3}) &lt;&lt; "\n";
  
      return 0;
  }
  </code></pre>
  
  <p>Using a const vector:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  
  using namespace std;
  
  int sumV(const vector&lt;int&gt; l){
      int sum = 0;
      for (const auto i: l){
          sum += i;
      }
      return sum;
  }
  
  int main(){
  
      cout &lt;&lt; sumV({1, 2, 3}) &lt;&lt; "\n";
      return 0;
  }
  </code></pre>