We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
template <class U1 = Ty1, class U2 = Ty2, typename std::enable_if< std::is_copy_constructible::value && std::is_copy_constructible::value && std::is_convertible<const U1&, Ty1>::value && std::is_convertible<const U2&, Ty2>::value, int>::type = 0> constexpr pair(const Ty1& a, const Ty2& b) : first(a), second(b) { }
// explicit constructible for this type template <class U1 = Ty1, class U2 = Ty2, typename std::enable_if< std::is_copy_constructible::value && std::is_copy_constructible::value && (!std::is_convertible<const U1&, Ty1>::value || !std::is_convertible<const U2&, Ty2>::value), int>::type = 0> explicit constexpr pair(const Ty1& a, const Ty2& b) : first(a), second(b) { }
The text was updated successfully, but these errors were encountered:
is_convertible<const U1&, Ty1> 与 is_convertible<U1, Ty1> 含义确实不一样。
is_convertible<const U1&, Ty1>
is_convertible<U1, Ty1>
Sorry, something went wrong.
其实,只有pair的两个参数被实例化为引用类型即,pair<int&, double&>,第一个构造函数才会被调用,而此时U和T都为引用类型,在std::is_convertible<const U1&, Ty1>::value中的const U1&,const只是顶层const,给引用类型加顶层const并没用,所以std::is_convertible<const U1&, Ty1>::value = 1,也就是说此时同样的std::is_convertible<U1, Ty1>::value = 1,所以 虽然is_convertible<const U1&, Ty1> 与 is_convertible<U1, Ty1> 含义确实不一样,但是在这里编译器认为它们的含义一样
No branches or pull requests
template <class U1 = Ty1, class U2 = Ty2,
typename std::enable_if<
std::is_copy_constructible::value &&
std::is_copy_constructible::value &&
std::is_convertible<const U1&, Ty1>::value &&
std::is_convertible<const U2&, Ty2>::value, int>::type = 0>
constexpr pair(const Ty1& a, const Ty2& b)
: first(a), second(b)
{
}
// explicit constructible for this type
template <class U1 = Ty1, class U2 = Ty2,
typename std::enable_if<
std::is_copy_constructible::value &&
std::is_copy_constructible::value &&
(!std::is_convertible<const U1&, Ty1>::value ||
!std::is_convertible<const U2&, Ty2>::value), int>::type = 0>
explicit constexpr pair(const Ty1& a, const Ty2& b)
: first(a), second(b)
{
}
The text was updated successfully, but these errors were encountered: