123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- #ifndef BOOST_COMPUTE_ALGORITHM_STABLE_PARTITION_HPP
- #define BOOST_COMPUTE_ALGORITHM_STABLE_PARTITION_HPP
- #include <boost/static_assert.hpp>
- #include <boost/compute/system.hpp>
- #include <boost/compute/context.hpp>
- #include <boost/compute/functional.hpp>
- #include <boost/compute/command_queue.hpp>
- #include <boost/compute/algorithm/copy_if.hpp>
- #include <boost/compute/container/vector.hpp>
- #include <boost/compute/type_traits/is_device_iterator.hpp>
- namespace boost {
- namespace compute {
- template<class Iterator, class UnaryPredicate>
- inline Iterator stable_partition(Iterator first,
- Iterator last,
- UnaryPredicate predicate,
- command_queue &queue = system::default_queue())
- {
- BOOST_STATIC_ASSERT(is_device_iterator<Iterator>::value);
- typedef typename std::iterator_traits<Iterator>::value_type value_type;
-
- ::boost::compute::vector<value_type> tmp(first, last, queue);
-
- Iterator last_true =
- ::boost::compute::copy_if(tmp.begin(),
- tmp.end(),
- first,
- predicate,
- queue);
-
- Iterator last_false =
- ::boost::compute::copy_if(tmp.begin(),
- tmp.end(),
- last_true,
- not1(predicate),
- queue);
-
- return last_true;
- }
- }
- }
- #endif
|