Open Quuxplusone opened 5 years ago
Survey of existing practice (that is, of people who provide a single-header implementation, because I'm lazy): https://godbolt.org/z/PGx6JA
std::function
happily permits converting int(*)()
to function<void()>
.
boost::function
happily permits converting int(*)()
to function<void()>
.
https://github.com/TartanLlama/function_ref tl::function_ref
consistently forbids converting int(*)()
to function<void()>
.
https://github.com/Naios/function2 fu2::function
claims to permit converting int(*)()
to function<void()>
, but if you try it, you get a hard error from the guts of the vtable.
After #155, inplace_function
claims to permit converting int(*)()
to function<void()>
, but if you try it, you get a hard error from the guts of the vtable.
I'd be interested to learn what happens with folly::function
; with HPX unique_function
; and/or with MongoDB unique_function
. But they're not single-header Godbolt-friendly, so I didn't really try hard.
Related to #149.
The above test case currently does not compile. Clang's error message is:
If we fix #149, then we must make a design decision here: should this code compile (as it does with
std::function
), or should it fail to compile (because returning42
from a function with signaturevoid(int)
usually indicates a programming error)? https://quuxplusone.github.io/blog/2019/01/06/hyper-function/ is related.