TartanLlama / function_ref

A lightweight, non-owning reference to a callable.
Creative Commons Zero v1.0 Universal
169 stars 23 forks source link

Cannot construct function_ref from function taking std::function as argument #14

Closed no-more-secrets closed 5 years ago

no-more-secrets commented 5 years ago

Here is a simple reproducer that is giving me a compiler error on the latest clang:

using FuncGood = tl::function_ref<void(int, int)>;
FuncGood good = []( int, int ){}; // ok

using FuncBad = tl::function_ref<void(int, std::function<void()>)>;
FuncBad bad = []( int, std::function<void()> ){}; // compile error

In particular, the error message says that the desired constructor is not viable because the condition detail::is_invocable_r is not holding true, so I'm thinking there might be an issue with your implementation of is_invocable_r?

Relevant part of error message (I believe):

function_ref/function_ref.hpp:144:15: note: candidate constructor not viable: no known conversion from '(lambda at main.cpp:121:19)' to 'const function_ref<void (int, std::__1::function<void ()>)> &' for 1st argument function_ref/function_ref.hpp:153:32: note: candidate template ignored: requirement 'detail::is_invocable_r_impl<std::__1::integral_constant<bool, true>, void, (lambda at main.cpp:121:19) &&, int, std::__1::function<void ()> >::value' was not satisfied [with F = (lambda at main.cpp:121:19)]
TartanLlama commented 5 years ago

I can't reproduce this: https://godbolt.org/z/HY3EH2 Can you post exact version of Clang and compiler flags, or ideally a Compiler Explorer link?

no-more-secrets commented 5 years ago

Ok I updated my version of function_ref and the issue went away, so must have been fixed since I cloned my copy in late June 2019. Thanks