Skip to content

Commit 7d8a243

Browse files
committed
Add default template argument tests. Improve replace_copy tests
1 parent 450250c commit 7d8a243

File tree

2 files changed

+70
-3
lines changed

2 files changed

+70
-3
lines changed

test/parallel_api/algorithm/alg.modifying.operations/remove_copy.pass.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,30 @@ test(T trash, const T& value, Convert convert, bool check_weakness = true)
9696
}
9797
}
9898

99+
struct not_implicitly_convertible
100+
{
101+
explicit not_implicitly_convertible(int v) {}
102+
};
103+
104+
template <typename It, typename DestIt, typename Void = void>
105+
struct is_remove_copy_well_formed : std::false_type {};
106+
107+
template <typename It, typename DestIt>
108+
struct is_remove_copy_well_formed<It, DestIt,
109+
std::void_t<decltype(oneapi::dpl::remove_copy(oneapi::dpl::execution::seq,
110+
std::declval<It>(),
111+
std::declval<It>(),
112+
std::declval<DestIt>(),
113+
{3}))>> : std::true_type {};
114+
115+
constexpr void test_default_template_argument_from_output_iterator()
116+
{
117+
static_assert(is_remove_copy_well_formed<std::vector<int>::iterator, std::vector<not_implicitly_convertible>::iterator>::value,
118+
"Positive: The default argument of remove_copy shall be taken from input iterator");
119+
static_assert(!is_remove_copy_well_formed<std::vector<not_implicitly_convertible>::iterator, std::vector<int>::iterator>::value,
120+
"Negative: The default argument of remove_copy shall be taken from input iterator");
121+
}
122+
99123
void test_empty_list_initialization()
100124
{
101125
{
@@ -164,6 +188,7 @@ main()
164188
[](std::int32_t j) { return ((j + 1) % 3 & 2) != 0 ? Number(2001, OddTag()) : Number(j, OddTag()); });
165189
#endif
166190

191+
test_default_template_argument_from_output_iterator();
167192
test_empty_list_initialization();
168193

169194
return done();

test/parallel_api/algorithm/alg.modifying.operations/replace_copy.pass.cpp

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,20 +109,61 @@ struct test_non_const
109109
}
110110
};
111111

112+
struct not_implicitly_convertible
113+
{
114+
explicit not_implicitly_convertible(int v) {}
115+
};
116+
117+
template <typename It, typename DestIt, typename Void = void>
118+
struct is_replace_copy_well_formed : std::false_type {};
119+
120+
template <typename It, typename DestIt>
121+
struct is_replace_copy_well_formed<It, DestIt,
122+
std::void_t<decltype(oneapi::dpl::replace_copy(oneapi::dpl::execution::seq,
123+
std::declval<It>(),
124+
std::declval<It>(),
125+
std::declval<DestIt>(),
126+
{2},
127+
{3}))>> : std::true_type {};
128+
129+
template <typename It, typename DestIt, typename Void = void>
130+
struct is_replace_copy_if_well_formed : std::false_type {};
131+
132+
template <typename It, typename DestIt>
133+
struct is_replace_copy_if_well_formed<It, DestIt,
134+
std::void_t<decltype(oneapi::dpl::replace_copy_if(oneapi::dpl::execution::seq,
135+
std::declval<It>(),
136+
std::declval<It>(),
137+
std::declval<DestIt>(),
138+
int{}, // actually, some callable should be here but since the function does not have any constraints any type will work
139+
{3}))>> : std::true_type {};
140+
141+
constexpr void test_default_template_argument_from_output_iterator()
142+
{
143+
static_assert(is_replace_copy_well_formed<std::vector<not_implicitly_convertible>::iterator, std::vector<int>::iterator>::value,
144+
"Positive: The default argument of replace_copy shall be taken from output iterator");
145+
static_assert(!is_replace_copy_well_formed<std::vector<int>::iterator, std::vector<not_implicitly_convertible>::iterator>::value,
146+
"Negative: The default argument of replace_copy shall be taken from output iterator");
147+
static_assert(is_replace_copy_if_well_formed<std::vector<not_implicitly_convertible>::iterator, std::vector<int>::iterator>::value,
148+
"Positive: The default argument of replace_copy_if shall be taken from output iterator");
149+
static_assert(!is_replace_copy_if_well_formed<std::vector<int>::iterator, std::vector<not_implicitly_convertible>::iterator>::value,
150+
"Positive: The default argument of replace_copy_if shall be taken from output iterator");
151+
}
152+
112153
void test_empty_list_initialization_for_replace_copy()
113154
{
114155
{
115156
std::vector<int> v{3,6,0,4,0,7,8,0,3,4};
116157
std::vector<int> dest(v.size());
117158
std::vector<int> expected{0,6,0,4,0,7,8,0,0,4};
118-
oneapi::dpl::replace_copy(oneapi::dpl::execution::seq, v.begin(), v.end(), dest.begin(), 3, {});
159+
oneapi::dpl::replace_copy(oneapi::dpl::execution::seq, v.begin(), v.end(), dest.begin(), {3}, {});
119160
EXPECT_TRUE(dest == expected, "wrong effect from calling oneapi::dpl::replace_copy with empty list-initialized value and with `seq` policy");
120161
}
121162
{
122163
std::vector<int> v{3,6,0,4,0,7,8,0,3,4};
123164
std::vector<int> dest(v.size());
124165
std::vector<int> expected{0,6,0,4,0,7,8,0,0,4};
125-
oneapi::dpl::replace_copy(oneapi::dpl::execution::unseq, v.begin(), v.end(), dest.begin(), 3, {});
166+
oneapi::dpl::replace_copy(oneapi::dpl::execution::unseq, v.begin(), v.end(), dest.begin(), {3}, {});
126167
EXPECT_TRUE(dest == expected, "wrong effect from calling oneapi::dpl::replace_copy with empty list-initialized value and with `unseq` policy");
127168
}
128169

@@ -148,7 +189,7 @@ void test_empty_list_initialization_for_replace_copy()
148189
std::vector<int> expected{0,6,0,4,0,7,8,0,0,4};
149190
sycl::buffer<int> buf(v);
150191
sycl::buffer<int> dest_buf(v);
151-
oneapi::dpl::replace_copy(oneapi::dpl::execution::dpcpp_default, oneapi::dpl::begin(buf), oneapi::dpl::end(buf), oneapi::dpl::begin(dest_buf), 3, {});
192+
oneapi::dpl::replace_copy(oneapi::dpl::execution::dpcpp_default, oneapi::dpl::begin(buf), oneapi::dpl::end(buf), oneapi::dpl::begin(dest_buf), {3}, {});
152193
EXPECT_TRUE(dest == expected, "wrong effect from calling oneapi::dpl::replace_copy with empty list-initialized value and with `device_policy` policy");
153194
#endif
154195
}
@@ -220,6 +261,7 @@ main()
220261
test_algo_basic_double<std::int32_t>(run_for_rnd_fw<test_non_const<std::int32_t>>());
221262
#endif
222263

264+
test_default_template_argument_from_output_iterator();
223265
test_empty_list_initialization_for_replace_copy();
224266
test_empty_list_initialization_for_replace_copy_if();
225267

0 commit comments

Comments
 (0)