equal.hpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. //---------------------------------------------------------------------------//
  2. // Copyright (c) 2013 Kyle Lutz <[email protected]>
  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_HPP
  11. #define BOOST_COMPUTE_ALGORITHM_EQUAL_HPP
  12. #include <boost/static_assert.hpp>
  13. #include <boost/compute/system.hpp>
  14. #include <boost/compute/command_queue.hpp>
  15. #include <boost/compute/algorithm/mismatch.hpp>
  16. #include <boost/compute/type_traits/is_device_iterator.hpp>
  17. namespace boost {
  18. namespace compute {
  19. /// Returns \c true if the range [\p first1, \p last1) and the range
  20. /// beginning at \p first2 are equal.
  21. ///
  22. /// Space complexity: \Omega(1)
  23. template<class InputIterator1, class InputIterator2>
  24. inline bool equal(InputIterator1 first1,
  25. InputIterator1 last1,
  26. InputIterator2 first2,
  27. command_queue &queue = system::default_queue())
  28. {
  29. BOOST_STATIC_ASSERT(is_device_iterator<InputIterator1>::value);
  30. BOOST_STATIC_ASSERT(is_device_iterator<InputIterator2>::value);
  31. return ::boost::compute::mismatch(first1,
  32. last1,
  33. first2,
  34. queue).first == last1;
  35. }
  36. /// \overload
  37. template<class InputIterator1, class InputIterator2>
  38. inline bool equal(InputIterator1 first1,
  39. InputIterator1 last1,
  40. InputIterator2 first2,
  41. InputIterator2 last2,
  42. command_queue &queue = system::default_queue())
  43. {
  44. BOOST_STATIC_ASSERT(is_device_iterator<InputIterator1>::value);
  45. BOOST_STATIC_ASSERT(is_device_iterator<InputIterator2>::value);
  46. if(std::distance(first1, last1) != std::distance(first2, last2)){
  47. return false;
  48. }
  49. return ::boost::compute::equal(first1, last1, first2, queue);
  50. }
  51. } // end compute namespace
  52. } // end boost namespace
  53. #endif // BOOST_COMPUTE_ALGORITHM_EQUAL_HPP