title: Saving image with libpng - const object
body: <p>I have a class which manages a grayscale image. I want to save it with libpng. To do that I want to use a <code>const</code> member function like this:</p>
  
  <pre><code>void GrayscaleImage::SavePNG(std::string filename) const
  {
      // ...
      png_bytep* row_pointers = new png_bytep[m_height];
      for (int i = 0; i &lt; height_; i++) {
          row_pointers[i] = const_cast&lt;png_bytep&gt;(m_data.data()) +  i * m_width * sizeof(uint8_t);
      }
      png_set_rows(png_ptr, info_ptr, row_pointers);
      // ...
  }
  </code></pre>
  
  <p>The problem is that the third argument of <code>png_set_rows</code> is non-const, so I have to use <code>const_cast</code> at some point, if I want the member function <code>GrayscaleImage::SavePNG</code> to be <code>const</code>. I'm wondering, is it safe to do this?</p>