Skip to content

Commit a65302a

Browse files
bernhardmgrubermiscco
authored andcommitted
Assure placeholder expressions are semi-regular (#2305)
1 parent 6ebc9a4 commit a65302a

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

thrust/testing/functional_placeholders_miscellaneous.cu

+18
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,21 @@ void TestFunctionalPlaceholdersArgumentValueCategories()
9191
ASSERT_EQUAL(expr(::cuda::std::move(a), ::cuda::std::move(b)), 13); // pass x-value
9292
}
9393
DECLARE_UNITTEST(TestFunctionalPlaceholdersArgumentValueCategories);
94+
95+
void TestFunctionalPlaceholdersSemiRegular()
96+
{
97+
using namespace thrust::placeholders;
98+
using Expr = decltype(_1 * _1 + _2 * _2);
99+
Expr expr; // default-constructible
100+
ASSERT_EQUAL(expr(2, 3), 13);
101+
Expr expr2 = expr; // copy-constructible
102+
ASSERT_EQUAL(expr2(2, 3), 13);
103+
Expr expr3;
104+
expr3 = expr; // copy-assignable
105+
ASSERT_EQUAL(expr3(2, 3), 13);
106+
107+
#if _CCCL_STD_VER >= 2014
108+
static_assert(::cuda::std::semiregular<Expr>, "");
109+
#endif // _CCCL_STD_VER >= 2014
110+
}
111+
DECLARE_UNITTEST(TestFunctionalPlaceholdersSemiRegular);

thrust/thrust/detail/functional/actor.h

+6
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ struct composite;
102102
template <typename Eval, typename SubExpr>
103103
struct composite<Eval, SubExpr>
104104
{
105+
constexpr composite() = default;
106+
105107
// TODO(bgruber): drop ctor and use aggregate initialization in C++17
106108
_CCCL_HOST_DEVICE composite(const Eval& eval, const SubExpr& subexpr)
107109
: m_eval(eval)
@@ -123,6 +125,8 @@ struct composite<Eval, SubExpr>
123125
template <typename Eval, typename SubExpr1, typename SubExpr2>
124126
struct composite<Eval, SubExpr1, SubExpr2>
125127
{
128+
constexpr composite() = default;
129+
126130
// TODO(bgruber): drop ctor and use aggregate initialization in C++17
127131
_CCCL_HOST_DEVICE composite(const Eval& eval, const SubExpr1& subexpr1, const SubExpr2& subexpr2)
128132
: m_eval(eval)
@@ -151,6 +155,8 @@ struct actor;
151155
template <typename F>
152156
struct operator_adaptor : F
153157
{
158+
constexpr operator_adaptor() = default;
159+
154160
_CCCL_HOST_DEVICE operator_adaptor(F f)
155161
: F(::cuda::std::move(f))
156162
{}

0 commit comments

Comments
 (0)