Changeset 3285
- Timestamp:
- Jul 11, 2014, 12:59:46 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/utility.cc
r3255 r3285 35 35 36 36 #include <boost/concept_archetype.hpp> 37 #include <boost/iterator/iterator_archetypes.hpp> 37 38 38 39 #include <cassert> … … 533 534 // do not run compiler tests 534 535 if (false) { 535 std::vector<size_t> vec;536 536 // value type must be possible to store in a vector so has to be 537 537 // default constructible and assignable … … 541 541 boost::input_iterator_archetype<value_type> iter; 542 542 utility::sort_index(iter, iter, vec); 543 543 544 // try with a random access container as well 544 std::vector<value_type> vec2; 545 utility::sort_index(vec2.begin(), vec2.end(), vec); 545 typedef boost::iterator_archetypes::readable_iterator_t access_type; 546 typedef boost::random_access_traversal_tag traversal_type; 547 typedef boost::copy_constructible_archetype< 548 boost::less_than_comparable_archetype<> > value_type2; 549 boost::iterator_archetype<value_type2, access_type, traversal_type> iter2; 550 utility::sort_index(iter2, iter2, vec); 546 551 } 547 552 // same thing with four argument version 548 553 if (false) { 549 std::vector<size_t> vec;550 554 // value type must be possible to store in a vector so has to be 551 555 // default constructible and assignable … … 555 559 boost::input_iterator_archetype<value_type> iter; 556 560 557 // Create a binary predicate that is assignable and default constructible 558 boost::default_constructible_archetype< 559 boost::sgi_assignable_archetype< 560 boost::binary_predicate_archetype< 561 value_type, value_type> > > comp; 561 // Create a binary predicate that is copy constructible 562 boost::copy_constructible_archetype< 563 boost::binary_predicate_archetype<value_type, value_type> 564 > comp; 562 565 563 566 utility::sort_index(iter, iter, vec, comp); 564 // try with a random access container as well 565 std::vector<value_type> vec2; 566 utility::sort_index(vec2.begin(), vec2.end(), vec, comp); 567 568 // try with a random access iterator as well 569 typedef boost::iterator_archetypes::readable_iterator_t access_type; 570 typedef boost::random_access_traversal_tag traversal_type; 571 typedef boost::copy_constructible_archetype<> value_type2; 572 boost::iterator_archetype<value_type2, access_type, traversal_type> iter2; 573 // Create a binary predicate that is copy constructible 574 boost::copy_constructible_archetype< 575 boost::binary_predicate_archetype<value_type2, value_type2> 576 > comp2; 577 utility::sort_index(iter2, iter2, vec, comp2); 567 578 } 568 579 } -
trunk/yat/utility/sort_index.h
r3238 r3285 24 24 25 25 #include <boost/concept_check.hpp> 26 #include <boost/iterator/iterator_categories.hpp> 27 #include <boost/iterator/iterator_concepts.hpp> 28 #include <boost/iterator/iterator_traits.hpp> 26 29 27 30 #include <algorithm> … … 49 52 <a href=http://www.sgi.com/tech/stl/LessThanComparable.html> 50 53 LessThan Comparable</a> 51 - \c InputIterator::value_type is 52 <a href=http://www.sgi.com/tech/stl/DefaultConstructible.html> 53 Default Constructible</a> and 54 - Either \c InputIterator::value_type is <a 55 href=http://www.sgi.com/tech/stl/DefaultConstructible.html> 56 Default Constructible</a> or \c InputIterator is 57 \random_access_traversal_iterator. 58 - Either \c InputIterator::value_type is 54 59 <a href=http://www.sgi.com/tech/stl/Assignable.html> 55 Assignable</a> 60 Assignable</a> or \c InputIterator is 61 \random_access_traversal_iterator. 56 62 57 63 \since New in yat 0.5. In versions prior 0.13 function was restricted to … … 68 74 Type Requirements: 69 75 - \c InputIterator is a model of \input_iterator 76 - Either \c InputIterator::value_type is <a 77 href=http://www.sgi.com/tech/stl/DefaultConstructible.html> 78 Default Constructible</a> or \c InputIterator is 79 \random_access_traversal_iterator. 80 - Either \c InputIterator::value_type is 81 <a href=http://www.sgi.com/tech/stl/Assignable.html> 82 Assignable</a> or \c InputIterator is 83 \random_access_traversal_iterator. 70 84 - \c Compare is a model of 71 85 <a href="http://www.sgi.com/tech/stl/StrictWeakOrdering.html"> 72 86 Strict Weak Ordering</a> 73 87 - \c Compare is 74 <a href="http://www.sgi.com/tech/stl/Assignable.html"> 75 Assignable</a> 76 - \c InputIterator::value_type is 77 <a href=http://www.sgi.com/tech/stl/DefaultConstructible.html> 78 Default Constructible</a> and 79 <a href=http://www.sgi.com/tech/stl/Assignable.html> 80 Assignable</a> 88 <a href="http://www.sgi.com/tech/stl/CopyConstructible.html"> 89 Copy Constructible</a> 81 90 - \c InputIterator::value_type is convertible to \c Compare's 82 91 argument type … … 97 106 void sort_index(InputIterator first, InputIterator last, 98 107 std::vector<size_t>& idx, Compare comp, 99 std::input_iterator_tag);108 boost::single_pass_traversal_tag); 100 109 101 110 // Specialization for random access iterator … … 103 112 void sort_index(RandomAccessIterator first, RandomAccessIterator last, 104 113 std::vector<size_t>& idx, Compare comp, 105 std::random_access_iterator_tag);114 boost::random_access_traversal_tag); 106 115 107 116 … … 111 120 public: 112 121 sort_index_Compare(RandomAccessIterator it, Compare comp) 113 : data_(it), compare_(comp) {} 122 : data_(it), compare_(comp) 123 { 124 using boost_concepts::ReadableIterator; 125 BOOST_CONCEPT_ASSERT((ReadableIterator<RandomAccessIterator>)); 126 using boost_concepts::RandomAccessTraversal; 127 BOOST_CONCEPT_ASSERT((RandomAccessTraversal<RandomAccessIterator>)); 128 typedef 129 typename boost::iterator_reference<RandomAccessIterator>::type T; 130 BOOST_CONCEPT_ASSERT((boost::BinaryPredicate<Compare, T, T>)); 131 } 114 132 115 133 bool operator()(size_t i, size_t j) const … … 132 150 std::vector<size_t>& idx) 133 151 { 134 BOOST_CONCEPT_ASSERT((boost::InputIterator<InputIterator>)); 135 typedef typename std::iterator_traits<InputIterator>::value_type T; 136 BOOST_CONCEPT_ASSERT((boost::DefaultConstructible<T>)); 137 BOOST_CONCEPT_ASSERT((boost::SGIAssignable<T>)); 152 typedef typename boost::iterator_value<InputIterator>::type T; 153 // we use std::less<T> 138 154 BOOST_CONCEPT_ASSERT((boost::LessThanComparable<T>)); 139 155 sort_index(first, last, idx, std::less<T>()); … … 146 162 { 147 163 BOOST_CONCEPT_ASSERT((boost::InputIterator<InputIterator>)); 148 typedef typename std::iterator_traits<InputIterator> traits; 149 typedef typename std::iterator_traits<InputIterator>::value_type T; 150 BOOST_CONCEPT_ASSERT((boost::DefaultConstructible<T>)); 151 BOOST_CONCEPT_ASSERT((boost::SGIAssignable<T>)); 152 BOOST_CONCEPT_ASSERT((boost::Assignable<Compare>)); 153 154 typedef typename traits::iterator_category category; 155 detail::sort_index(first, last, idx, comp, category()); 164 typename boost::iterator_traversal<InputIterator>::type traversal; 165 detail::sort_index(first, last, idx, comp, traversal); 156 166 } 157 167 … … 165 175 void sort_index(InputIterator first, InputIterator last, 166 176 std::vector<size_t>& idx, Compare comp, 167 std::input_iterator_tag tag)177 boost::single_pass_traversal_tag tag) 168 178 { 169 typedef typename std::iterator_traits<InputIterator>::value_type T; 179 typedef typename boost::iterator_value<InputIterator>::type T; 180 // two concepts for vector<T> 181 BOOST_CONCEPT_ASSERT((boost::DefaultConstructible<T>)); 182 BOOST_CONCEPT_ASSERT((boost::SGIAssignable<T>)); 170 183 std::vector<T> vec(first, last); 171 184 sort_index(vec.begin(), vec.end(), idx, comp, 172 std::random_access_iterator_tag());185 boost::random_access_traversal_tag()); 173 186 } 174 187 175 // Specialization for random access iterator 188 189 // Specialization for random access traversal 176 190 template<typename RandomAccessIterator, class Compare> 177 191 void sort_index(RandomAccessIterator first, RandomAccessIterator last, 178 192 std::vector<size_t>& idx, Compare comp, 179 std::random_access_iterator_tag tag)193 boost::random_access_traversal_tag tag) 180 194 { 181 195 sort_index_Compare<RandomAccessIterator, Compare> compare(first, comp);
Note: See TracChangeset
for help on using the changeset viewer.