[Boost-bugs] [Boost C++ Libraries] #3996: Enable use of BOOST_FOREACH over const-ref of noncopyable ptr_containers

Subject: [Boost-bugs] [Boost C++ Libraries] #3996: Enable use of BOOST_FOREACH over const-ref of noncopyable ptr_containers
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2010-03-10 20:24:04


#3996: Enable use of BOOST_FOREACH over const-ref of noncopyable ptr_containers
-------------------------------------------------------+--------------------
 Reporter: Kazutoshi Satoda <k_satoda@…> | Owner: nesotto
     Type: Patches | Status: new
Milestone: Boost 1.43.0 | Component: ptr_container
  Version: Boost 1.42.0 | Severity: Problem
 Keywords: BOOST_FOREACH is_noncopyable |
-------------------------------------------------------+--------------------
 I have encountered an error about allocating abstract type, with the
 following code:
 {{{
 #include "boost/ptr_container/ptr_vector.hpp"
 #include "boost/foreach.hpp"
 struct S { virtual void f() const = 0; };
 typedef boost::ptr_vector<S> ptr_vector;
 void f(ptr_vector const& v) { BOOST_FOREACH(S const& s, v) s.f(); }
 }}}
 And I found this is a known issue:
 [http://www.boost.org/doc/libs/1_42_0/doc/html/foreach/extensibility.html#id862475
 Boost.Foreach > Extensibility]

 Then I thought that boost::foreach::is_noncopyable<> should be
 specialized for ptr_containers of which value_type is abstruct. Then I
 put the following:
 {{{
 namespace boost { namespace foreach {
   template<typename T, typename A, typenale CA>
   struct is_noncopyable<ptr_vector<T,A,CA> > : is_abstract<T> {};
 }}
 }}}
 ... and the error disappeared.

 After that, since ptr_container is designed to be an alternative of the
 standard containers for the case of the value is non-copyable, I thought
 this is a wide problem worth making a patch.

 The patch looks better than the above workaround in some points:
   - fixes the problem for all ptr_containers at once
   - also supports types marked by boost::noncopyable
   - keeps the container copyable if view_clone_allocator is used

 The patch also includes some test cases I actually used, while I have no
 idea how to integrate it into boost test infrastructure.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/3996>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:02 UTC