Skip to content

Commit 4689f86

Browse files
committed
Add better test of perfect forwarding of bound arguments
1 parent c7a6b18 commit 4689f86

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

libcxx/test/std/utilities/function.objects/func.bind.partial/bind_front.nttp.pass.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,21 @@ constexpr void test_perfect_forwarding_call_wrapper() {
268268
}
269269
}
270270

271+
{ // Test perfect forwarding when various overloads are available
272+
struct X {
273+
Tag<0> operator()(int&, char) const;
274+
Tag<1> operator()(const int&, char) const;
275+
Tag<2> operator()(int&&, char) const;
276+
Tag<3> operator()(const int&&, char) const;
277+
};
278+
279+
using F = decltype(std::bind_front<X{}>(0));
280+
static_assert(std::same_as<std::invoke_result_t<F&, char>, Tag<0>>);
281+
static_assert(std::same_as<std::invoke_result_t<const F&, char>, Tag<1>>);
282+
static_assert(std::same_as<std::invoke_result_t<F, char>, Tag<2>>);
283+
static_assert(std::same_as<std::invoke_result_t<const F, char>, Tag<3>>);
284+
}
285+
271286
{ // Test perfect forwarding
272287
auto f = [](int& val) {
273288
val = 5;

libcxx/test/std/utilities/function.objects/func.bind.partial/types.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,7 @@ struct MaybeNoexceptFn {
4545
bool operator()() const noexcept(IsNoexcept); // not defined
4646
};
4747

48+
template <int>
49+
struct Tag {};
50+
4851
#endif // TEST_STD_UTILITIES_FUNCTION_OBJECTS_FUNC_BIND_PARTIAL_TYPES_H

0 commit comments

Comments
 (0)