SFINAE内部概念

SFINAE是否在概念参数内起作用? (也许这里不叫SFINAE)。例:

template <class F>
    requires
        std::invocable<F, int> && // <-- is this needed?
        (!std::same_as<std::invoke_result_t<F, int>, void>)
auto foo(F f, int a) -> int

Is the above std::invocable<F, int> required?

如果我们这样忽略它:

template <class F>
    requires (!std::same_as<std::invoke_result_t<F, int>, void>)
auto foo(F f, int a) -> int

Is this version well-formed even if std::invoke_result_t<F, int> is not (i.e. if it is not invocable) or is it UB/ill formed, ndr?

foo(11, 24);
// std::invoke_result_t<int, int> does not exist,
// is the second variant the one without `std::invocable<F, int>` ok in this case?

gcc seems to behave without it: https://godbolt.org/z/SEH94-

评论