#192·MyTinySTL

util.h中pair构造函数重载问题

Author: huohuo132Created Apr 28, 2026Updated Apr 28, 2026

// implicit constructiable 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> 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) { } 85到107行,两个构造函数的模板都是template<class U1,class U2,int>::type 编译器可能会认为是重复定义,标准库里是用了void int bool三个类型 新手正在学习中,如有打扰请见谅