title: Wrapping C API taking raw pointers by C++ function that takes iterators
body: <p>What is the best way to wrap a C API that takes plain pointers by a funtion that takes iterators?</p>
  
  <p>I am trying to wrap a legacy API that takes pointers and size to contigious memory. However in my wrapper I would like to provide an iterator based interface.</p>
  
  <p>Here is an example to illustrate the problem:</p>
  
  <pre><code>// C-Api
  bool socket_send(void* buffer, size_t size);
  
  // C++ Wrapper
  class Socket {
      template &lt;...&gt;
      bool send(Iterator begin, Iterator end) {
           ...
      }
  };
  </code></pre>
  
  <p>One solution that comes to my mind is to create a vector and copy the values:</p>
  
  <pre><code>class Socket {
      template &lt;...&gt;
      bool send(Iterator begin, Iterator end) {
           std::vector&lt;...&gt; buff(begin, end);
           socket_send(buffer.data(), buffer.size()*sizeof(decltype(buffer)::value_type);
      }
  };
  </code></pre>
  
  <p>The problem, that I have with this solution, is the unneccessary copy of the data even if it is already contigious memory.</p>
  
  <p>Is there a generic and efficient solution around this problem?</p>