MyTinySTL icon indicating copy to clipboard operation
MyTinySTL copied to clipboard

关于rb_tree.h中定义的函数 rb_tree<T, Compare>:: find(const key_type& key)

Open dcstempt opened this issue 2 years ago • 1 comments

rb_tree<T, Compare>:: find(const key_type& key) const 函数定义中: 最后一行: return ( j == end() || key_comp_(key, value_traits::get_key(*j)) ) ? end() : j; 出现报错 error: operands to ?: have different types 报错指出:end()的类型为 mystl::rb_tree_const_iterator<int> j 的类型为 mystl::rb_tree_iterator<int> 因此,此处不能使用三元表达式,只能老老实实使用 if - else

dcstempt avatar Feb 22 '23 08:02 dcstempt

实际的 bug 应该是 mystl::rb_tree_iterator<int> ~不能隐式转换成 mystl::rb_tree_const_iterator<int>~ 和 mystl::rb_tree_const_iterator<int> 存在双向隐式转换。

应该只能从 mystl::rb_tree_iterator<int> 隐式转换成 mystl::rb_tree_const_iterator<int> 而不能反过来。

frederick-vs-ja avatar Oct 10 '23 11:10 frederick-vs-ja