title: Const correctness of STL library with reference-wrapper?
body: <p>I have the following class:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>class Data;
  class A
  {
  public:
      A(Data&amp; _data) : data(_data) {}
      Data&amp; getData() {return data;}
      const Data&amp; getData() const {return data;}
  private:
      Data&amp; data;
  };
  </code></pre>
  
  <p>Now imagine I need to keep not one, but multiple instances of Data. I keep them in a vector of reference wrappers, but I would also like to keep the const correctness: pass the data as unmodifiable in const context.</p>
  
  <pre class="lang-cpp prettyprint-override"><code>class A
  {
  public:
      void addData(Data&amp; _data) {data.push_back(std::ref(_data));}
      const std::vector&lt;std::reference_wrapper&lt;Data&gt;&gt;&amp; getData() {return data;}
      //doesn't compile
      //const std::vector&lt;std::reference_wrapper&lt;const Data&gt;&gt;&amp; getData() const {return data;}
  private:
      std::vector&lt;std::reference_wrapper&lt;Data&gt;&gt; data;
  }
  </code></pre>
  
  <p>How to implement this without having physical copying of the data? I.e. I don't want to return a copy of the vector by value and I don't want to keep two separate vectors in class A. Both are performance-impacting solutions for what is basically just a semantic problem.</p>