从 this answer 开始,似乎这些构造函数:
template<class U, class V> pair(pair<U, V>&& p);
template<class U, class V> pair(const pair<U, V>& p);
在需要显式转换时禁止参与重载决策。
来自 C++11(§20.3.2,n3290):
Remark: This constructor shall not participate in overload resolution unless U is implicitly convertible to first_type and V is implicitly convertible to second_type.
一个有趣的SFINAE workaround已被建议,但这偏离了标准的文本。
如果没有一些特殊的内部编译器魔法,一个符合规范的实现怎么可能将其排除在重载决议之外? IE。一个实现可以做到这一点吗?我可以为我自己的类型复制它吗?似乎没有任何符合这一点的!这是从 C++11 中删除概念的后遗症吗?
我确实想知道使用私有(private)构造函数来完成 SFINAE 部分并从公共(public)构造函数委托(delegate),但它看起来不像构造函数委托(delegate)以这种方式参与 SFINAE 以使其工作。
最佳答案
but this digresses from the text of the standard
允许一个实现向任何非虚拟库成员函数添加默认参数。这似乎恰好允许这种 SFINAE 技巧。
关于c++ - 排除使用显式构造的 std::pair 构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8137917/