Skip to content

Commit 0b48df1

Browse files
mfrancis95alliepiper
authored andcommitted
Use placeholder expressions
Use placeholder expression in thrust::count Use placeholder expression in thrust::find Use placeholder expression in thrust::mismatch Use placeholder expression in thrust::sequence Remove sequence_functor Use placeholder expression in thrust::remove Use placeholder expression in thrust::find Use placeholder expression in thrust::replace Use placeholder expression in thrust::replace Use placeholder expression in thrust::replace_copy Remove unneeded thrust/detail/internal_functional.h include from thrust/system/detail/generic/replace.inl
1 parent 543a365 commit 0b48df1

File tree

7 files changed

+26
-41
lines changed

7 files changed

+26
-41
lines changed

thrust/system/cuda/detail/find.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,12 @@ find(execution_policy<Derived> &policy,
205205
InputIt last,
206206
T const& value)
207207
{
208+
using thrust::placeholders::_1;
209+
208210
return cuda_cub::find_if(policy,
209211
first,
210212
last,
211-
thrust::detail::equal_to_value<T>(value));
213+
_1 == value);
212214
}
213215

214216

thrust/system/cuda/detail/remove.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,9 @@ remove(execution_policy<Derived> &policy,
7474
InputIt last,
7575
const T & value)
7676
{
77-
thrust::detail::equal_to_value<T> pred(value);
78-
return cuda_cub::remove_if(policy, first, last, pred);
77+
using thrust::placeholders::_1;
78+
79+
return cuda_cub::remove_if(policy, first, last, _1 == value);
7980
}
8081

8182
// copy

thrust/system/cuda/detail/replace.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,14 @@ replace(execution_policy<Derived> &policy,
9090
T const & old_value,
9191
T const & new_value)
9292
{
93+
using thrust::placeholders::_1;
94+
9395
cuda_cub::transform_if(policy,
9496
first,
9597
last,
9698
first,
9799
__replace::constant_f<T>(new_value),
98-
thrust::detail::equal_to_value<T>(old_value));
100+
_1 == old_value);
99101
}
100102

101103
template <class Derived,

thrust/system/detail/generic/find.inl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ InputIterator find(thrust::execution_policy<DerivedPolicy> &exec,
4545
InputIterator last,
4646
const T& value)
4747
{
48-
// XXX consider a placeholder expression here
49-
return thrust::find_if(exec, first, last, thrust::detail::equal_to_value<T>(value));
48+
using thrust::placeholders::_1;
49+
50+
return thrust::find_if(exec, first, last, _1 == value);
5051
} // end find()
5152

5253

thrust/system/detail/generic/mismatch.inl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,9 @@ __host__ __device__
3838
InputIterator1 last1,
3939
InputIterator2 first2)
4040
{
41-
typedef typename thrust::iterator_value<InputIterator1>::type InputType1;
42-
43-
// XXX use a placeholder expression here
44-
return thrust::mismatch(exec, first1, last1, first2, thrust::detail::equal_to<InputType1>());
41+
using namespace thrust::placeholders;
42+
43+
return thrust::mismatch(exec, first1, last1, first2, _1 == _2);
4544
} // end mismatch()
4645

4746

thrust/system/detail/generic/replace.inl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
*/
1616

1717
#include <thrust/detail/config.h>
18+
#include <thrust/functional.h>
1819
#include <thrust/system/detail/generic/replace.h>
1920
#include <thrust/transform.h>
2021
#include <thrust/replace.h>
21-
#include <thrust/detail/internal_functional.h>
2222

2323
namespace thrust
2424
{
@@ -124,8 +124,9 @@ __host__ __device__
124124
const T &old_value,
125125
const T &new_value)
126126
{
127-
thrust::detail::equal_to_value<T> pred(old_value);
128-
return thrust::replace_copy_if(exec, first, last, result, pred, new_value);
127+
using thrust::placeholders::_1;
128+
129+
return thrust::replace_copy_if(exec, first, last, result, _1 == old_value, new_value);
129130
} // end replace_copy()
130131

131132

@@ -164,8 +165,9 @@ __host__ __device__
164165
const T &old_value,
165166
const T &new_value)
166167
{
167-
thrust::detail::equal_to_value<T> pred(old_value);
168-
return thrust::replace_if(exec, first, last, pred, new_value);
168+
using thrust::placeholders::_1;
169+
170+
return thrust::replace_if(exec, first, last, _1 == old_value, new_value);
169171
} // end replace()
170172

171173

thrust/system/detail/generic/sequence.inl

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
#include <thrust/detail/config.h>
18+
#include <thrust/functional.h>
1819
#include <thrust/system/detail/generic/sequence.h>
1920
#include <thrust/iterator/iterator_traits.h>
2021
#include <thrust/tabulate.h>
@@ -27,30 +28,6 @@ namespace detail
2728
{
2829
namespace generic
2930
{
30-
namespace sequence_detail
31-
{
32-
33-
34-
template<typename T>
35-
struct sequence_functor
36-
{
37-
T init, step;
38-
39-
__host__ __device__
40-
sequence_functor(T init, T step)
41-
: init(init), step(step)
42-
{}
43-
44-
template<typename Index>
45-
__host__ __device__
46-
T operator()(Index i) const
47-
{
48-
return static_cast<T>(init + step * i);
49-
}
50-
};
51-
52-
53-
} // end sequence_detail
5431

5532

5633
template<typename DerivedPolicy, typename ForwardIterator>
@@ -84,8 +61,9 @@ __host__ __device__
8461
T init,
8562
T step)
8663
{
87-
// XXX TODO use a placeholder expression here
88-
thrust::tabulate(exec, first, last, sequence_detail::sequence_functor<T>(init, step));
64+
using thrust::placeholders::_1;
65+
66+
thrust::tabulate(exec, first, last, init + step * _1);
8967
} // end sequence()
9068

9169

0 commit comments

Comments
 (0)