title: How to release std string from memory management duties?
body: <p>I have a string by value and a function that takes in a char pointer and length and when finished calls a callback which is a lambda expression provided on that function call. I want my string data to be deallocated on that callback -not when scope exits. There is no move into lambda in c++11 and current wrapper implementations I found can not be passed as void(*fun)() function arguments. Are there ways to move string or release it from its memory duties in c++11?</p>
  
  <p>So original API was in C</p>
  
  <pre><code>void Send(const void * _topic, int length, void (*OnSend)());
  </code></pre>
  
  <p>That activated other sender thread and called OnSend after sending data. Zero-Copy was main point of all this.</p>
  
  <p>And I wanted to call it from C++ and move into this a real string, keeping zero-copy.</p>
  
  <p>Ended up with rewriting core API in C++ - doing such thing from C without Pools/const size Ring buffers is really hard! So having a <code>std::function</code> and <code>std::bind</code> it all gets much simpler. Yet now C API wraps C++ one...</p>
  
  <p>While C++ part looks like this:</p>
  
  <pre><code>void Send(std::string &amp;&amp; _data) {
      const auto data_ptr = &amp;_data;
  
      std::function&lt;void()&gt; OnDataRemoval = std::bind(
          [](std::string &amp;&amp; d){},
              std::move(_data)
      );
  
       Send(data_ptr, OnDataRemoval);
  }
  </code></pre>