BLI: fix overload resolution with FunctionRef parameters
This commit is contained in:
parent
fd887bcb15
commit
153e1c0492
|
@ -111,7 +111,8 @@ template<typename Ret, typename... Params> class FunctionRef<Ret(Params...)> {
|
|||
*/
|
||||
template<typename Callable,
|
||||
BLI_ENABLE_IF((
|
||||
!std::is_same_v<std::remove_cv_t<std::remove_reference_t<Callable>>, FunctionRef>))>
|
||||
!std::is_same_v<std::remove_cv_t<std::remove_reference_t<Callable>>, FunctionRef>)),
|
||||
BLI_ENABLE_IF((std::is_invocable_r_v<Ret, Callable, Params...>))>
|
||||
FunctionRef(Callable &&callable)
|
||||
: callback_(callback_fn<typename std::remove_reference_t<Callable>>),
|
||||
callable_(intptr_t(&callable))
|
||||
|
|
|
@ -130,4 +130,23 @@ TEST(function_ref, InitializeWithNull)
|
|||
EXPECT_FALSE(f);
|
||||
}
|
||||
|
||||
static int overload_test(const FunctionRef<void(std::string)> /*fn*/)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int overload_test(const FunctionRef<void(int)> /*fn*/)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
TEST(function_ref, OverloadSelection)
|
||||
{
|
||||
const auto fn_1 = [](std::string /*x*/) {};
|
||||
const auto fn_2 = [](int /*x*/) {};
|
||||
|
||||
EXPECT_EQ(overload_test(fn_1), 1);
|
||||
EXPECT_EQ(overload_test(fn_2), 2);
|
||||
}
|
||||
|
||||
} // namespace blender::tests
|
||||
|
|
Loading…
Reference in New Issue