Ticket #3996: ptr_container_propagate_noncopyable_for_foreach.patch
File ptr_container_propagate_noncopyable_for_foreach.patch, 4.2 KB (added by , 13 years ago) |
---|
-
boost/ptr_container/detail/reversible_ptr_container.hpp
35 35 #include <boost/utility/enable_if.hpp> 36 36 #include <boost/type_traits/is_pointer.hpp> 37 37 #include <boost/type_traits/is_integral.hpp> 38 #include <boost/type_traits/is_same.hpp> 39 #include <boost/mpl/if.hpp> 40 #include <boost/mpl/and.hpp> 41 #include <boost/mpl/not.hpp> 42 #include <boost/noncopyable.hpp> 38 43 #include <boost/swap.hpp> 39 44 #include <typeinfo> 40 45 #include <memory> … … 48 53 namespace boost 49 54 { 50 55 56 // minimum declaration required by propagate_noncopyable_for_foreach 57 namespace foreach { template< class T > struct is_noncopyable; } 58 51 59 namespace ptr_container_detail 52 60 { 53 61 template< class Container > … … 93 101 struct associative_container_tag {}; 94 102 struct ordered_associative_container_tag : associative_container_tag {}; 95 103 struct unordered_associative_container_tag : associative_container_tag {}; 96 97 104 105 // Mark the ptr_container with boost::noncopyable as appropreate to 106 // enable use of BOOST_FOREACH over const reference of ptr_container 107 // of which value_type is noncopyable. 108 // See: http://www.boost.org/doc/html/foreach/extensibility.html#id862475 109 struct copyable {}; // dummy 110 template<typename ValueType, typename CloneAllocator> 111 struct propagate_noncopyable_for_foreach 112 : mpl::if_< 113 mpl::and_< 114 mpl::not_<boost::is_same<CloneAllocator, view_clone_allocator> >, 115 boost::foreach::is_noncopyable<ValueType> 116 >, 117 boost::noncopyable, 118 copyable 119 >::type {}; 98 120 99 121 template 100 122 < 101 123 class Config, 102 124 class CloneAllocator 103 125 > 104 class reversible_ptr_container : CloneAllocator 126 class reversible_ptr_container : CloneAllocator, 127 private propagate_noncopyable_for_foreach< 128 BOOST_DEDUCED_TYPENAME Config::value_type, CloneAllocator> 105 129 { 106 130 private: 107 131 BOOST_STATIC_CONSTANT( bool, allow_null = Config::allow_null ); -
libs/ptr_container/test/foreach_noncopyable_detection.cpp
1 #include "boost/ptr_container/ptr_vector.hpp" 2 #include "boost/ptr_container/ptr_map.hpp" 3 #include "boost/ptr_container/ptr_set.hpp" 4 #include "boost/foreach.hpp" 5 6 struct normal {}; 7 bool operator < (normal const&, normal const&); 8 9 struct abstract { virtual void f() const = 0; }; 10 bool operator < (abstract const&, abstract const&); 11 12 struct noncopyable : boost::noncopyable {}; 13 bool operator < (noncopyable const&, noncopyable const&); 14 15 16 using boost::foreach::is_noncopyable; 17 18 template<typename T, typename CloneAllocator, bool ExpectedNoncopyable> 19 struct test_noncopyable 20 { 21 typedef boost::ptr_vector<T, CloneAllocator> sequence; 22 BOOST_STATIC_ASSERT(is_noncopyable<sequence>::value == ExpectedNoncopyable); 23 24 typedef boost::ptr_set<T, std::less<T>, CloneAllocator> set; 25 BOOST_STATIC_ASSERT(is_noncopyable<set>::value == ExpectedNoncopyable); 26 27 typedef boost::ptr_map<normal, T, std::less<normal>, CloneAllocator> map; 28 BOOST_STATIC_ASSERT(is_noncopyable<map>::value == ExpectedNoncopyable); 29 }; 30 31 32 test_noncopyable<normal, boost::heap_clone_allocator, false> 33 normal_container_should_be_copyable; 34 35 test_noncopyable<normal, boost::view_clone_allocator, false> 36 normal_view_should_be_copyable; 37 38 test_noncopyable<abstract, boost::heap_clone_allocator, true> 39 abstract_container_should_be_noncopyable; 40 41 test_noncopyable<abstract, boost::view_clone_allocator, false> 42 abstract_view_should_be_copyable; 43 44 test_noncopyable<noncopyable, boost::heap_clone_allocator, true> 45 noncopyable_container_should_be_noncopyable; 46 47 test_noncopyable<noncopyable, boost::view_clone_allocator, false> 48 noncopyable_view_should_be_copyable;