Ticket #3996: ptr_container_propagate_noncopyable_for_foreach.2.patch
File ptr_container_propagate_noncopyable_for_foreach.2.patch, 4.0 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> 44 #include <boost/foreach_extensibility.hpp> 39 45 #include <typeinfo> 40 46 #include <memory> 41 47 … … 93 99 struct associative_container_tag {}; 94 100 struct ordered_associative_container_tag : associative_container_tag {}; 95 101 struct unordered_associative_container_tag : associative_container_tag {}; 96 97 102 103 // Mark the ptr_container with boost::noncopyable as appropreate to 104 // enable use of BOOST_FOREACH over const reference of ptr_container 105 // of which value_type is noncopyable. 106 // See: http://www.boost.org/doc/html/foreach/extensibility.html#id862475 107 struct copyable {}; // dummy 108 template<typename ValueType, typename CloneAllocator> 109 struct propagate_noncopyable_for_foreach 110 : mpl::if_< 111 mpl::and_< 112 mpl::not_<boost::is_same<CloneAllocator, view_clone_allocator> >, 113 boost::foreach::is_noncopyable<ValueType> 114 >, 115 boost::noncopyable, 116 copyable 117 >::type {}; 98 118 99 119 template 100 120 < 101 121 class Config, 102 122 class CloneAllocator 103 123 > 104 class reversible_ptr_container : CloneAllocator 124 class reversible_ptr_container : CloneAllocator, 125 private propagate_noncopyable_for_foreach< 126 BOOST_DEDUCED_TYPENAME Config::value_type, CloneAllocator> 105 127 { 106 128 private: 107 129 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;