find_end.hpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. // Copyright Neil Groves 2009. Use, modification and
  2. // distribution is subject to the Boost Software License, Version
  3. // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. //
  6. //
  7. // For more information, see http://www.boost.org/libs/range/
  8. //
  9. #ifndef BOOST_RANGE_ALGORITHM_FIND_END_HPP_INCLUDED
  10. #define BOOST_RANGE_ALGORITHM_FIND_END_HPP_INCLUDED
  11. #include <boost/concept_check.hpp>
  12. #include <boost/range/begin.hpp>
  13. #include <boost/range/end.hpp>
  14. #include <boost/range/concepts.hpp>
  15. #include <boost/range/detail/range_return.hpp>
  16. #include <algorithm>
  17. namespace boost
  18. {
  19. namespace range
  20. {
  21. /// \brief template function find_end
  22. ///
  23. /// range-based version of the find_end std algorithm
  24. ///
  25. /// \pre ForwardRange1 is a model of the ForwardRangeConcept
  26. /// \pre ForwardRange2 is a model of the ForwardRangeConcept
  27. /// \pre BinaryPredicate is a model of the BinaryPredicateConcept
  28. template< class ForwardRange1, class ForwardRange2 >
  29. inline BOOST_DEDUCED_TYPENAME disable_if<
  30. is_const<ForwardRange1>,
  31. BOOST_DEDUCED_TYPENAME range_iterator< ForwardRange1 >::type
  32. >::type
  33. find_end(ForwardRange1 & rng1, const ForwardRange2& rng2)
  34. {
  35. BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<ForwardRange1> ));
  36. BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<const ForwardRange2> ));
  37. return std::find_end(boost::begin(rng1),boost::end(rng1),
  38. boost::begin(rng2),boost::end(rng2));
  39. }
  40. /// \overload
  41. template< class ForwardRange1, class ForwardRange2 >
  42. inline BOOST_DEDUCED_TYPENAME range_iterator< const ForwardRange1 >::type
  43. find_end(const ForwardRange1 & rng1, const ForwardRange2& rng2)
  44. {
  45. BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<const ForwardRange1> ));
  46. BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<const ForwardRange2> ));
  47. return std::find_end(boost::begin(rng1),boost::end(rng1),
  48. boost::begin(rng2),boost::end(rng2));
  49. }
  50. /// \overload
  51. template< class ForwardRange1, class ForwardRange2, class BinaryPredicate >
  52. inline BOOST_DEDUCED_TYPENAME disable_if<
  53. is_const<ForwardRange1>,
  54. BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange1>::type
  55. >::type
  56. find_end(ForwardRange1 & rng1, const ForwardRange2& rng2, BinaryPredicate pred)
  57. {
  58. BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<ForwardRange1> ));
  59. BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<const ForwardRange2> ));
  60. return std::find_end(boost::begin(rng1),boost::end(rng1),
  61. boost::begin(rng2),boost::end(rng2),pred);
  62. }
  63. /// \overload
  64. template< class ForwardRange1, class ForwardRange2, class BinaryPredicate >
  65. inline BOOST_DEDUCED_TYPENAME range_iterator<const ForwardRange1>::type
  66. find_end(const ForwardRange1& rng1, const ForwardRange2& rng2, BinaryPredicate pred)
  67. {
  68. BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<const ForwardRange1> ));
  69. BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<const ForwardRange2> ));
  70. return std::find_end(boost::begin(rng1),boost::end(rng1),
  71. boost::begin(rng2),boost::end(rng2),pred);
  72. }
  73. /// \overload
  74. template< range_return_value re, class ForwardRange1, class ForwardRange2 >
  75. inline BOOST_DEDUCED_TYPENAME disable_if<
  76. is_const<ForwardRange1>,
  77. BOOST_DEDUCED_TYPENAME range_return<ForwardRange1,re>::type
  78. >::type
  79. find_end(ForwardRange1& rng1, const ForwardRange2& rng2)
  80. {
  81. BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<ForwardRange1> ));
  82. BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<const ForwardRange2> ));
  83. return range_return<ForwardRange1,re>::
  84. pack(std::find_end(boost::begin(rng1), boost::end(rng1),
  85. boost::begin(rng2), boost::end(rng2)),
  86. rng1);
  87. }
  88. /// \overload
  89. template< range_return_value re, class ForwardRange1, class ForwardRange2 >
  90. inline BOOST_DEDUCED_TYPENAME range_return<const ForwardRange1,re>::type
  91. find_end(const ForwardRange1& rng1, const ForwardRange2& rng2)
  92. {
  93. BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<const ForwardRange1> ));
  94. BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<const ForwardRange2> ));
  95. return range_return<const ForwardRange1,re>::
  96. pack(std::find_end(boost::begin(rng1), boost::end(rng1),
  97. boost::begin(rng2), boost::end(rng2)),
  98. rng1);
  99. }
  100. /// \overload
  101. template< range_return_value re, class ForwardRange1, class ForwardRange2,
  102. class BinaryPredicate >
  103. inline BOOST_DEDUCED_TYPENAME disable_if<
  104. is_const<ForwardRange1>,
  105. BOOST_DEDUCED_TYPENAME range_return<ForwardRange1,re>::type
  106. >::type
  107. find_end(ForwardRange1& rng1, const ForwardRange2& rng2, BinaryPredicate pred)
  108. {
  109. BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<ForwardRange1> ));
  110. BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<const ForwardRange2> ));
  111. return range_return<ForwardRange1,re>::
  112. pack(std::find_end(boost::begin(rng1), boost::end(rng1),
  113. boost::begin(rng2), boost::end(rng2), pred),
  114. rng1);
  115. }
  116. /// \overload
  117. template< range_return_value re, class ForwardRange1, class ForwardRange2,
  118. class BinaryPredicate >
  119. inline BOOST_DEDUCED_TYPENAME range_return<const ForwardRange1,re>::type
  120. find_end(const ForwardRange1& rng1, const ForwardRange2& rng2, BinaryPredicate pred)
  121. {
  122. BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<const ForwardRange1> ));
  123. BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<const ForwardRange2> ));
  124. return range_return<const ForwardRange1,re>::
  125. pack(std::find_end(boost::begin(rng1), boost::end(rng1),
  126. boost::begin(rng2), boost::end(rng2), pred),
  127. rng1);
  128. }
  129. } // namespace range
  130. using range::find_end;
  131. } // namespace boost
  132. #endif // include guard