为什么 std::is_constructible 在直接上下文中停止?

Why std::is_constructible stops at immediate context?

源自 topic. Also related to this topic

我的问题是,为什么 std::is_constructible 停在当前上下文?我认为 std::is_constructible 的用户会期望它能够全面深入地工作并给出准确的答案。有了这个直接的上下文,你可能 std::is_constructible 给你开了绿灯,但当你真正这样做的时候却得到了一个硬编译器错误。这不是违背了std::is_constructible的初衷。现在,它对我来说基本上看起来没用。我想 std::looks_constructible_at_first_sight 对于当前的语义来说是一个更好的名字 :(

如果构造函数的签名比应有的宽松得多,那是的问题 - 而不是 is_constructible 的实现。在您的原始示例中,

template <typename... Ts, typename=decltype(base{std::declval<Ts>()...})>
aggregate_wrapper(Ts&&... xs)
    : base{std::forward<Ts>(xs)...} {/*…*/}

完成任务。如果 is_constructible "spuriously" 亮绿灯,那么您的构造函数模板可能会被错误地选择为优于其他构造函数,因为重载解析发现它是最佳匹配。

但是,重载解决方案并非旨在只提供真值 negatives/positives:它旨在找到给定适当参数的最佳匹配,或者如果争论是不够恰当的。 is_constructible 在某种意义上可能是肤浅的,但这就是特征的用途 - 检查签名,这是一个实体在重载决议和 SFINAE 领域的表示 - 不阻止你的函数模板接受一切但实际上只是为争论的余地很小。
那是你的责任,如果你做到了,你就会从 is_constructible 和高效的编译中得到正确的结果。这绝对比 is_constructible 的可靠运行和在函数模板调用中具有大量隐藏规则的高编译时间要好。