Boost C++ Libraries: Ticket #5816: any_range requires copyable elements https://svn.boost.org/trac10/ticket/5816 <p> boost::any_range attempts to copy container elements even if the <em>Reference</em> template parameter is a reference. This behavior prevents the use of noncopyable element types and is inconsistent with boost::sub_range and boost::iterator_range. </p> <p> Short code example that doesn't compile (unless <em>private:</em> is commented out): </p> <pre class="wiki">#include &lt;boost/range/concepts.hpp&gt; // because any_range.hpp doesn't compile alone #include &lt;boost/range/any_range.hpp&gt; #include &lt;vector&gt; // X is movable, but non-copyable class X { public: X() {} X(X&amp;&amp;) {} void operator= (X&amp;&amp;) {} private: X(const X&amp;); void operator= (const X&amp;); }; int main() { std::vector&lt;X&gt; v; boost::any_range&lt;X, boost::random_access_traversal_tag, X&amp;, std::ptrdiff_t&gt; range2 = v; } </pre><p> The problem might be in line 429 of any_iterator_wrapper.hpp, where <em>reference_as_value_type</em> is used for the <em>Reference</em> template parameter of the underlying <em>any_random_access_iterator_wrapper</em>. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/5816 Trac 1.4.3 voivoid@… Fri, 18 Oct 2013 13:57:20 GMT <link>https://svn.boost.org/trac10/ticket/5816#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5816#comment:1</guid> <description> <p> This problem also prevents a use of abstract class pointers. Any chances this is going to be fixed? </p> <p> I wonder if the problem could be solved with something like this: </p> <pre class="wiki">any_iterator_interface.hpp 49,51c49,53 &lt; typedef typename remove_const&lt; &lt; typename remove_reference&lt;Reference&gt;::type &lt; &gt;::type reference_as_value_type; --- &gt; typedef typename mpl::if_&lt; &gt; is_trivially_copy_constructible&lt;typename remove_reference&lt;Reference&gt;::type&gt; &gt; , typename remove_const&lt;typename remove_reference&lt;Reference&gt;::type&gt;::type &gt; , Reference &gt; &gt;::type reference_as_value_type; </pre><p> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Tue, 04 Feb 2014 07:52:00 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5816#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5816#comment:2</guid> <description> <p> I also encountered this problem recently. It prevents me from using boost::any_range as an object interface abstraction, since i don't want the values copied (i want to expose iterators to Base, and supply a container of Derived objects in the implementation). </p> <p> I do not see any good reason to require copying when all any_range is is an abstract view into the source range. That elements aren't going to be copied should be made into a guarantee. </p> <p> This is a 2 year old bug, is it possible that it can be fixed soon? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Neil Groves</dc:creator> <pubDate>Fri, 21 Feb 2014 20:28:11 GMT</pubDate> <title>status changed https://svn.boost.org/trac10/ticket/5816#comment:3 https://svn.boost.org/trac10/ticket/5816#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> <p> Yes it will be fixed soon. I've got a bunch more time than I have and I'm trying hard to catch up. </p> Ticket Neil Groves Sun, 02 Mar 2014 23:03:43 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/5816#comment:4 https://svn.boost.org/trac10/ticket/5816#comment:4 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> Ticket