Boost C++ Libraries: Ticket #11731: iostreams classes do not support C++11 move semantics https://svn.boost.org/trac10/ticket/11731 <p> At least some iostreams classes do not support C++11 move semantics. Attempts to "move-construct" them result in compiler errors. Such classes include but are probably not limited to filtering_istream. </p> <p> #include &lt;boost/iostreams/filtering_stream.hpp&gt; </p> <p> struct Foo { </p> <blockquote> <p> Foo(Foo&amp;&amp; o) </p> <blockquote> <p> : f(std::move(o.f)) { } </p> </blockquote> <p> boost::iostreams::filtering_istream f; </p> </blockquote> <p> }; </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/11731 Trac 1.4.3 ki.stfu@… Thu, 26 Jan 2017 06:10:42 GMT <link>https://svn.boost.org/trac10/ticket/11731#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11731#comment:1</guid> <description> <p> Hi! </p> <p> I faced with the same problem when I tried to move <code>boost::iostreams::stream&lt;&gt;</code>. Here is my app: </p> <pre class="wiki">#include &lt;cassert&gt; #include &lt;iostream&gt; #include &lt;fstream&gt; #include &lt;boost/iostreams/stream.hpp&gt; class MyDevice { public: typedef char char_type; typedef boost::iostreams::sink_tag category; explicit MyDevice(int i) { assert(i == 1); } std::streamsize write(const char_type* s, std::streamsize n) { std::cout &lt;&lt; s &lt;&lt; '\n'; return n; } }; boost::iostreams::stream&lt;MyDevice&gt; make_stream(int i) { return boost::iostreams::stream&lt;MyDevice&gt; (i); // ERROR } std::ofstream make_ofstream() { return std::ofstream ("test.txt", std::ofstream::out); } int main() { auto&amp;&amp; strm = make_stream(1); // ERROR strm &lt;&lt; "12312313"; boost::iostreams::stream&lt;MyDevice&gt; strm2(1); // OK strm2 &lt;&lt; "12312313"; make_ofstream() &lt;&lt; " asdfasdf"; // OK for clang++-3.8 with -stdlib=libc++ return 0; } </pre><p> I found couple classes that prevent compiler from implicitly-declaring move constructors. These classes have user-declared copy constructor/destructor and because of this reason we have to implement move operators by ourselves. </p> <pre class="wiki">diff --git a/include/boost/iostreams/detail/buffer.hpp b/include/boost/iostreams/detail/buffer.hpp index 72400f0..5174253 100644 --- a/include/boost/iostreams/detail/buffer.hpp +++ b/include/boost/iostreams/detail/buffer.hpp @@ -46,6 +46,7 @@ private: public: basic_buffer(); basic_buffer(std::streamsize buffer_size); + basic_buffer(basic_buffer&amp;&amp;) { /* TODO implement move ctor and assign op */ } ~basic_buffer(); void resize(std::streamsize buffer_size); Ch* begin() const { return buf_; } diff --git a/include/boost/iostreams/detail/optional.hpp b/include/boost/iostreams/detail/optional.hpp index 867dfbd..5067a97 100644 --- a/include/boost/iostreams/detail/optional.hpp +++ b/include/boost/iostreams/detail/optional.hpp @@ -49,6 +49,7 @@ public: typedef T element_type; optional() : initialized_(false) { } optional(const T&amp; t) : initialized_(false) { reset(t); } + optional(optional&amp;&amp;) { /* TODO implement move ctor and assign op */ } ~optional() { reset(); } T&amp; operator*() { diff --git a/include/boost/iostreams/stream_buffer.hpp b/include/boost/iostreams/stream_buffer.hpp index dbcb786..f9e54b7 100644 --- a/include/boost/iostreams/stream_buffer.hpp +++ b/include/boost/iostreams/stream_buffer.hpp @@ -84,6 +84,7 @@ public: BOOST_IOSTREAMS_STREAMBUF_TYPEDEFS(Tr) public: stream_buffer() { } + stream_buffer(stream_buffer&amp;&amp; that) { /* TODO implement move ctor and assign op */ } ~stream_buffer() { try { </pre><p> Can anyone look into this issue? </p> </description> <category>Ticket</category> </item> <item> <author>ki.stfu@…</author> <pubDate>Thu, 26 Jan 2017 06:12:26 GMT</pubDate> <title>version changed; cc set https://svn.boost.org/trac10/ticket/11731#comment:2 https://svn.boost.org/trac10/ticket/11731#comment:2 <ul> <li><strong>cc</strong> <span class="trac-author">ki.stfu@…</span> added </li> <li><strong>version</strong> <span class="trac-field-old">Boost 1.57.0</span> → <span class="trac-field-new">Boost Development Trunk</span> </li> </ul> Ticket