title: Trying to change a value in a vector bool
body: <p>I'm reading Stroustrup PPP and while doing an exercise, I found this error.</p>
  <h2>Why I can't change the value of a vector bool?</h2>
  <pre class="lang-cpp prettyprint-override"><code>#include &quot;std_lib_facilities.h&quot;
  
  int main()
  {
    vector&lt;bool&gt; vecc(2, true);
  
    vecc[1] = true; // I can't do this, returns error.
  
    return 0;
  }
  </code></pre>
  <p>The error:</p>
  <p><code>error: cannot bind non-const lvalue reference of type 'bool&amp;' to an rvalue of type 'bool' return std::vector&lt;T&gt;::operator[](i);</code></p>
  <p>Second, when I try with the int type, the problem does not occur.</p>
  <pre class="lang-cpp prettyprint-override"><code>#include &quot;std_lib_facilities.h&quot;
  
  int main(){
    vector&lt;int&gt; vecc = {true, true};
  
  
    for(bool x : vecc) {cout&lt;&lt;x&lt;&lt;&quot;\n&quot;;}
  
    vecc[1] = false; //ok
  
    for(bool x : vecc){cout&lt;&lt;x&lt;&lt;&quot;\n&quot;;}
    return 0;
  }
  </code></pre>
  <p>Output:</p>
  <pre><code>1
  1
  1
  0
  </code></pre>
  <h3>Edit:</h3>
  <p>Probably this is because I was using <code>#include &quot;std_lib_facilities.h&quot;</code></p>
  <p><a href="https://www.stroustrup.com/Programming/std_lib_facilities.h" rel="nofollow noreferrer">std_lib_facilities.h</a></p>