File indexing completed on 2025-01-18 09:29:58
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_COMPUTE_ALGORITHM_STABLE_PARTITION_HPP
0012 #define BOOST_COMPUTE_ALGORITHM_STABLE_PARTITION_HPP
0013
0014 #include <boost/static_assert.hpp>
0015
0016 #include <boost/compute/system.hpp>
0017 #include <boost/compute/context.hpp>
0018 #include <boost/compute/functional.hpp>
0019 #include <boost/compute/command_queue.hpp>
0020 #include <boost/compute/algorithm/copy_if.hpp>
0021 #include <boost/compute/container/vector.hpp>
0022 #include <boost/compute/type_traits/is_device_iterator.hpp>
0023
0024 namespace boost {
0025 namespace compute {
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043 template<class Iterator, class UnaryPredicate>
0044 inline Iterator stable_partition(Iterator first,
0045 Iterator last,
0046 UnaryPredicate predicate,
0047 command_queue &queue = system::default_queue())
0048 {
0049 BOOST_STATIC_ASSERT(is_device_iterator<Iterator>::value);
0050 typedef typename std::iterator_traits<Iterator>::value_type value_type;
0051
0052
0053 ::boost::compute::vector<value_type> tmp(first, last, queue);
0054
0055
0056 Iterator last_true =
0057 ::boost::compute::copy_if(tmp.begin(),
0058 tmp.end(),
0059 first,
0060 predicate,
0061 queue);
0062
0063
0064 Iterator last_false =
0065 ::boost::compute::copy_if(tmp.begin(),
0066 tmp.end(),
0067 last_true,
0068 not1(predicate),
0069 queue);
0070
0071
0072 return last_true;
0073 }
0074
0075 }
0076 }
0077
0078 #endif