Skip to content

Commit d3de1b1

Browse files
committed
Merge branch 'cmake_love' of github.com:TartanLlama/function_ref into cmake_love
2 parents 52047cc + 1f47ba3 commit d3de1b1

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

include/tl/function_ref.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ struct is_invocable_r_impl : std::false_type {};
116116

117117
template <class R, class F, class... Args>
118118
struct is_invocable_r_impl<
119-
typename std::is_same<invoke_result_t<F, Args...>, R>::type, R, F, Args...>
119+
typename std::is_convertible<invoke_result_t<F, Args...>, R>::type, R, F, Args...>
120120
: std::true_type {};
121121

122122
template <class R, class F, class... Args>
@@ -153,7 +153,7 @@ template <class R, class... Args> class function_ref<R(Args...)> {
153153
detail::is_invocable_r<R, F &&, Args...>::value> * = nullptr>
154154
TL_FUNCTION_REF_11_CONSTEXPR function_ref(F &&f) noexcept
155155
: obj_(const_cast<void*>(reinterpret_cast<const void *>(std::addressof(f)))) {
156-
callback_ = [](void *obj, Args... args) {
156+
callback_ = [](void *obj, Args... args) -> R {
157157
return detail::invoke(
158158
*reinterpret_cast<typename std::add_pointer<F>::type>(obj),
159159
std::forward<Args>(args)...);

tests/issues.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,18 @@ TEST_CASE("Issue #2") {
55
const auto lam = [](int ) {};
66
tl::function_ref<void(int)> ref = lam;
77
(void)ref;
8+
}
9+
10+
struct Fruit {};
11+
struct Apple : Fruit {};
12+
13+
Apple* getApple() { return nullptr; }
14+
15+
tl::function_ref<Fruit* ()> bar()
16+
{
17+
return getApple;
18+
}
19+
20+
TEST_CASE("Issue #9") {
21+
REQUIRE(bar()() == nullptr);
822
}

0 commit comments

Comments
 (0)