Boost C++ Libraries: Ticket #1070: [iostreams]boost\iostreams\copy.hpp line80 copy_impl https://svn.boost.org/trac10/ticket/1070 <p> boost\iostreams\copy.hpp line 80 - line 100 </p> <div class="wiki-code"><div class="code"><pre><span class="k">template</span><span class="o">&lt;</span><span class="k">typename</span> <span class="n">Source</span><span class="p">,</span> <span class="k">typename</span> <span class="n">Sink</span><span class="o">&gt;</span> <span class="n">std</span><span class="o">::</span><span class="n">streamsize</span> <span class="n">copy_impl</span><span class="p">(</span> <span class="n">Source</span><span class="o">&amp;</span> <span class="n">src</span><span class="p">,</span> <span class="n">Sink</span><span class="o">&amp;</span> <span class="n">snk</span><span class="p">,</span> <span class="n">std</span><span class="o">::</span><span class="n">streamsize</span> <span class="n">buffer_size</span><span class="p">,</span> <span class="n">mpl</span><span class="o">::</span><span class="n">false_</span><span class="p">,</span> <span class="n">mpl</span><span class="o">::</span><span class="n">true_</span> <span class="p">)</span> <span class="p">{</span> <span class="c1">// Copy from an indirect Source to a direct Sink.</span> <span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span> <span class="k">typedef</span> <span class="k">typename</span> <span class="n">char_type_of</span><span class="o">&lt;</span><span class="n">Source</span><span class="o">&gt;::</span><span class="n">type</span> <span class="n">char_type</span><span class="p">;</span> <span class="k">typedef</span> <span class="n">pair</span><span class="o">&lt;</span><span class="n">char_type</span><span class="o">*</span><span class="p">,</span> <span class="n">char_type</span><span class="o">*&gt;</span> <span class="n">pair_type</span><span class="p">;</span> <span class="n">detail</span><span class="o">::</span><span class="n">basic_buffer</span><span class="o">&lt;</span><span class="n">char_type</span><span class="o">&gt;</span> <span class="n">buf</span><span class="p">(</span><span class="n">buffer_size</span><span class="p">);</span> <span class="n">pair_type</span> <span class="n">p</span> <span class="o">=</span> <span class="n">snk</span><span class="p">.</span><span class="n">output_sequence</span><span class="p">();</span> <span class="n">streamsize</span> <span class="n">total</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="kt">bool</span> <span class="n">done</span> <span class="o">=</span> <span class="nb">false</span><span class="p">;</span> <span class="k">while</span> <span class="p">(</span><span class="o">!</span><span class="n">done</span><span class="p">)</span> <span class="p">{</span> <span class="n">streamsize</span> <span class="n">amt</span><span class="p">;</span> <span class="n">done</span> <span class="o">=</span> <span class="p">(</span><span class="n">amt</span> <span class="o">=</span> <span class="n">iostreams</span><span class="o">::</span><span class="n">read</span><span class="p">(</span><span class="n">src</span><span class="p">,</span> <span class="n">buf</span><span class="p">.</span><span class="n">data</span><span class="p">(),</span> <span class="n">buffer_size</span><span class="p">))</span> <span class="o">==</span> <span class="o">-</span><span class="mi">1</span><span class="p">;</span> <span class="n">std</span><span class="o">::</span><span class="n">copy</span><span class="p">(</span><span class="n">buf</span><span class="p">.</span><span class="n">data</span><span class="p">(),</span> <span class="n">buf</span><span class="p">.</span><span class="n">data</span><span class="p">()</span> <span class="o">+</span> <span class="n">amt</span><span class="p">,</span> <span class="n">p</span><span class="p">.</span><span class="n">first</span> <span class="o">+</span> <span class="n">total</span><span class="p">);</span> <span class="k">if</span> <span class="p">(</span><span class="n">amt</span> <span class="o">!=</span> <span class="o">-</span><span class="mi">1</span><span class="p">)</span> <span class="n">total</span> <span class="o">+=</span> <span class="n">amt</span><span class="p">;</span> <span class="p">}</span> <span class="k">return</span> <span class="n">total</span><span class="p">;</span> <span class="p">}</span> </pre></div></div><p> When "iostreams::read" return -1 ,amt equal -1,it will assert in std::copy because iterator last &lt; first. </p> <p> Please read <a class="ext-link" href="http://article.gmane.org/gmane.comp.lib.boost.devel/161764"><span class="icon">​</span>http://article.gmane.org/gmane.comp.lib.boost.devel/161764</a> for detail. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/1070 Trac 1.4.3 qbowater@… Fri, 06 Jul 2007 08:01:48 GMT <link>https://svn.boost.org/trac10/ticket/1070#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1070#comment:1</guid> <description> <div class="wiki-code"> <div class="diff"> <ul class="entries"> <li class="entry"> <h2> <a>.hpp</a> </h2> <table class="trac-diff inline" cellspacing="0"> <colgroup> <col class="lineno"/><col class="lineno"/><col class="content"/> </colgroup> <thead> <tr> <th title="File copy.hpp 2005-05-26 01:37:30.000000000 +0800"> old </th> <th title="File copy1.hpp 2007-07-06 15:55:17.859375000 +0800"> new </th> <td> <em></em> &nbsp; </td> </tr> </thead> <tbody class="unmod"> <tr> <th>88</th><th>88</th><td class="l"><span>&nbsp; &nbsp; detail::basic_buffer&lt;char_type&gt;&nbsp; buf(buffer_size);</span></td> </tr> <tr> <th>89</th><th>89</th><td class="l"><span>&nbsp; &nbsp; pair_type&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; p = snk.output_sequence();</span></td> </tr> <tr> <th>90</th><th>90</th><td class="l"><span>&nbsp; &nbsp; streamsize&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;total = 0;</span></td> </tr> </tbody> <tbody class="mod"> <tr class="first"> <th>91</th><th>&nbsp;</th><td class="l"><span>&nbsp; &nbsp; <del>bool&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;done&nbsp; = false;</del></span></td> </tr> <tr> <th>92</th><th>&nbsp;</th><td class="l"><span>&nbsp; &nbsp; <del>while (!done) {</del></span></td> </tr> <tr> <th>93</th><th>&nbsp;</th><td class="l"><span>&nbsp; &nbsp; &nbsp; &nbsp; <del>streamsize amt;</del></span></td> </tr> <tr> <th>94</th><th>&nbsp;</th><td class="l"><span>&nbsp; &nbsp; &nbsp; &nbsp; <del>done = (amt = iostreams::read(src, buf.data(), buffer_size)) == -1</del>;</span></td> </tr> <tr> <th>&nbsp;</th><th>91</th><td class="r"><span>&nbsp; &nbsp; <ins>while (true) {</ins></span></td> </tr> <tr> <th>&nbsp;</th><th>92</th><td class="r"><span>&nbsp; &nbsp; <ins>&nbsp; &nbsp; streamsize amt = iostreams::read(src, buf.data(), buffer_size);</ins></span></td> </tr> <tr> <th>&nbsp;</th><th>93</th><td class="r"><span>&nbsp; &nbsp; &nbsp; &nbsp; <ins>if(amt == -1)</ins></span></td> </tr> <tr class="last"> <th>&nbsp;</th><th>94</th><td class="r"><span>&nbsp; &nbsp; &nbsp; &nbsp; <ins>&nbsp; &nbsp; break</ins>;</span></td> </tr> </tbody> <tbody class="unmod"> <tr> <th>95</th><th>95</th><td class="l"><span>&nbsp; &nbsp; &nbsp; &nbsp; std::copy(buf.data(), buf.data() + amt, p.first + total);</span></td> </tr> </tbody> <tbody class="mod"> <tr class="first"> <th>96</th><th>&nbsp;</th><td class="l"><span>&nbsp; &nbsp; &nbsp; &nbsp; if (amt != -1)</span></td> </tr> <tr> <th>97</th><th>&nbsp;</th><td class="l"><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; total += amt;</span></td> </tr> <tr class="last"> <th>&nbsp;</th><th>96</th><td class="r"><span>&nbsp; &nbsp; &nbsp; &nbsp; total += amt;</span></td> </tr> </tbody> <tbody class="unmod"> <tr> <th>98</th><th>97</th><td class="l"><span>&nbsp; &nbsp; }</span></td> </tr> <tr> <th>99</th><th>98</th><td class="l"><span>&nbsp; &nbsp; return total;</span></td> </tr> <tr> <th>100</th><th>99</th><td class="l"><span>}</span></td> </tr> </tbody> <tbody class="skipped"> <tr> <th><a href="#L109">&hellip;</a></th> <th><a href="#L108">&hellip;</a></th> <td> <em></em> &nbsp; </td> </tr> </tbody> <tbody class="unmod"> <tr> <th>109</th><th>108</th><td class="l"><span>&nbsp; &nbsp; detail::basic_buffer&lt;char_type&gt;&nbsp; buf(buffer_size);</span></td> </tr> <tr> <th>110</th><th>109</th><td class="l"><span>&nbsp; &nbsp; non_blocking_adapter&lt;Sink&gt;&nbsp; &nbsp; &nbsp; &nbsp;nb(snk);</span></td> </tr> <tr> <th>111</th><th>110</th><td class="l"><span>&nbsp; &nbsp; std::streamsize&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; total = 0;</span></td> </tr> </tbody> <tbody class="mod"> <tr class="first"> <th>112</th><th>&nbsp;</th><td class="l"><span>&nbsp; &nbsp; bool&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;done = false;</span></td> </tr> <tr> <th>113</th><th>&nbsp;</th><td class="l"><span>&nbsp; &nbsp; while (!done) {</span></td> </tr> <tr> <th>114</th><th>&nbsp;</th><td class="l"><span>&nbsp; &nbsp; &nbsp; &nbsp; std::streamsize amt;</span></td> </tr> <tr> <th>115</th><th>&nbsp;</th><td class="l"><span>&nbsp; &nbsp; &nbsp; &nbsp; done = (amt = iostreams::read(src, buf.data(), buffer_size)) == -1;</span></td> </tr> <tr> <th>116</th><th>&nbsp;</th><td class="l"><span>&nbsp; &nbsp; &nbsp; &nbsp; if (amt != -1) {</span></td> </tr> <tr> <th>117</th><th>&nbsp;</th><td class="l"><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; iostreams::write(nb, buf.data(), amt);</span></td> </tr> <tr> <th>118</th><th>&nbsp;</th><td class="l"><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; total += amt;</span></td> </tr> <tr> <th>119</th><th>&nbsp;</th><td class="l"><span>&nbsp; &nbsp; &nbsp; &nbsp; }</span></td> </tr> <tr> <th>&nbsp;</th><th>111</th><td class="r"><span>&nbsp; &nbsp; while (true) {</span></td> </tr> <tr> <th>&nbsp;</th><th>112</th><td class="r"><span>&nbsp; &nbsp; &nbsp; &nbsp; std::streamsize amt = iostreams::read(src, buf.data(), buffer_size);</span></td> </tr> <tr> <th>&nbsp;</th><th>113</th><td class="r"><span>&nbsp; &nbsp; &nbsp; &nbsp; if (amt == -1)</span></td> </tr> <tr> <th>&nbsp;</th><th>114</th><td class="r"><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;</span></td> </tr> <tr> <th>&nbsp;</th><th>115</th><td class="r"><span>&nbsp; &nbsp; &nbsp; &nbsp; iostreams::write(nb, buf.data(), amt);</span></td> </tr> <tr class="last"> <th>&nbsp;</th><th>116</th><td class="r"><span>&nbsp; &nbsp; &nbsp; &nbsp; total += amt;</span></td> </tr> </tbody> <tbody class="unmod"> <tr> <th>120</th><th>117</th><td class="l"><span>&nbsp; &nbsp; }</span></td> </tr> <tr> <th>121</th><th>118</th><td class="l"><span>&nbsp; &nbsp; return total;</span></td> </tr> <tr> <th>122</th><th>119</th><td class="l"><span>}</span></td> </tr> </tbody> </table> </li> </ul> </div></div><pre class="wiki">--- copy.hpp 2005-05-26 01:37:30.000000000 +0800 +++ copy1.hpp 2007-07-06 15:55:17.859375000 +0800 @@ -88,13 +88,12 @@ detail::basic_buffer&lt;char_type&gt; buf(buffer_size); pair_type p = snk.output_sequence(); streamsize total = 0; - bool done = false; - while (!done) { - streamsize amt; - done = (amt = iostreams::read(src, buf.data(), buffer_size)) == -1; + while (true) { + streamsize amt = iostreams::read(src, buf.data(), buffer_size); + if(amt == -1) + break; std::copy(buf.data(), buf.data() + amt, p.first + total); - if (amt != -1) - total += amt; + total += amt; } return total; } @@ -109,14 +108,12 @@ detail::basic_buffer&lt;char_type&gt; buf(buffer_size); non_blocking_adapter&lt;Sink&gt; nb(snk); std::streamsize total = 0; - bool done = false; - while (!done) { - std::streamsize amt; - done = (amt = iostreams::read(src, buf.data(), buffer_size)) == -1; - if (amt != -1) { - iostreams::write(nb, buf.data(), amt); - total += amt; - } + while (true) { + std::streamsize amt = iostreams::read(src, buf.data(), buffer_size); + if (amt == -1) + break; + iostreams::write(nb, buf.data(), amt); + total += amt; } return total; } </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Fri, 06 Jul 2007 23:04:52 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/1070#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1070#comment:2</guid> <description> <p> I think this is the same as Trac ticket # 786 </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Wed, 11 Jul 2007 04:18:54 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/1070#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1070#comment:3</guid> <description> <p> The proposed change at ticket <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/786" title="#786: Bugs: bug in iostreams/copy.hpp line 81 (closed: fixed)">#786</a> seems a little cleaner than the change here. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Peter Dimov</dc:creator> <pubDate>Sun, 22 Jul 2007 00:30:49 GMT</pubDate> <title>component, severity changed; owner set https://svn.boost.org/trac10/ticket/1070#comment:4 https://svn.boost.org/trac10/ticket/1070#comment:4 <ul> <li><strong>owner</strong> set to <span class="trac-author">Douglas Gregor</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">iostreams</span> </li> <li><strong>severity</strong> <span class="trac-field-old">Showstopper</span> → <span class="trac-field-new">Problem</span> </li> </ul> Ticket Peter Dimov Sun, 22 Jul 2007 00:32:57 GMT owner deleted https://svn.boost.org/trac10/ticket/1070#comment:5 https://svn.boost.org/trac10/ticket/1070#comment:5 <ul> <li><strong>owner</strong> <span class="trac-author">Douglas Gregor</span> removed </li> </ul> <p> How did the owner become dgregor? A Trac mystery. </p> Ticket Marshall Clow Thu, 27 Sep 2007 14:05:09 GMT owner set https://svn.boost.org/trac10/ticket/1070#comment:6 https://svn.boost.org/trac10/ticket/1070#comment:6 <ul> <li><strong>owner</strong> set to <span class="trac-author">Jonathan Turkanis</span> </li> </ul> Ticket Jonathan Turkanis Tue, 25 Dec 2007 08:51:48 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/1070#comment:7 https://svn.boost.org/trac10/ticket/1070#comment:7 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Fixed in <a class="changeset" href="https://svn.boost.org/trac10/changeset/42294" title="fixed issues #786 and (duplicate) #1070">[42294]</a> in branches/iostreams_dev, to be merged into trunk shortly. The fix is a slight modification of the suggestion in <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/786" title="#786: Bugs: bug in iostreams/copy.hpp line 81 (closed: fixed)">#786</a>. </p> Ticket