[PATCH] D96794: [ADT] Add SFINAE guards to unique_function constructor.

Sam McCall via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 16 13:16:56 PST 2021


sammccall added inline comments.


================
Comment at: llvm/include/llvm/ADT/FunctionExtras.h:361
+      detail::EnableUnlessSameType<CallableT, unique_function> * = nullptr,
+      detail::EnableIfCallable<CallableT, R, P...> * = nullptr)
       : Base(std::forward<CallableT>(Callable),
----------------
kadircet wrote:
> what about doing this in the constructor of the `UniqueFunctionBase` instead?
I don't think this works even in principle, only the signatures are taken into account when resolving overloads, and the base-initialization is not part of the signature.
https://godbolt.org/z/TWvcsE - see that the overload on the class with the sfinae constructor template works, but overloading on types derived from it is ambiguous.

Practically it also doesn't work because UniqueFunctionBase doesn't have access to R and P..., and you can't pass explicit template args to a constructor template.

(Or maybe I'm misunderstanding your suggestion)


================
Comment at: llvm/unittests/ADT/FunctionExtrasTest.cpp:267
+std::string returns(StringRef) { return "not a function"; }
+std::string returns(function_ref<double()> F) { return "number"; }
+std::string returns(function_ref<StringRef()> F) { return "string"; }
----------------
kadircet wrote:
> s/function_ref/unique_function/
> 
> here and below
Oops... need to do a *little* more than copy/paste...


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96794/new/

https://reviews.llvm.org/D96794



More information about the llvm-commits mailing list