equal_range.hpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. //---------------------------------------------------------------------------//
  2. // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
  3. //
  4. // Distributed under the Boost Software License, Version 1.0
  5. // See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt
  7. //
  8. // See http://boostorg.github.com/compute for more information.
  9. //---------------------------------------------------------------------------//
  10. #ifndef BOOST_COMPUTE_ALGORITHM_EQUAL_RANGE_HPP
  11. #define BOOST_COMPUTE_ALGORITHM_EQUAL_RANGE_HPP
  12. #include <utility>
  13. #include <boost/static_assert.hpp>
  14. #include <boost/compute/system.hpp>
  15. #include <boost/compute/command_queue.hpp>
  16. #include <boost/compute/algorithm/lower_bound.hpp>
  17. #include <boost/compute/algorithm/upper_bound.hpp>
  18. #include <boost/compute/type_traits/is_device_iterator.hpp>
  19. namespace boost {
  20. namespace compute {
  21. /// Returns a pair of iterators containing the range of values equal
  22. /// to \p value in the sorted range [\p first, \p last).
  23. ///
  24. /// Space complexity: \Omega(1)
  25. template<class InputIterator, class T>
  26. inline std::pair<InputIterator, InputIterator>
  27. equal_range(InputIterator first,
  28. InputIterator last,
  29. const T &value,
  30. command_queue &queue = system::default_queue())
  31. {
  32. BOOST_STATIC_ASSERT(is_device_iterator<InputIterator>::value);
  33. return std::make_pair(
  34. ::boost::compute::lower_bound(first, last, value, queue),
  35. ::boost::compute::upper_bound(first, last, value, queue)
  36. );
  37. }
  38. } // end compute namespace
  39. } // end boost namespace
  40. #endif // BOOST_COMPUTE_ALGORITHM_EQUAL_RANGE_HPP