MyTinySTL
MyTinySTL copied to clipboard
关于rb_tree.h中定义的函数 rb_tree<T, Compare>:: find(const key_type& key)
在
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
实际的 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>
而不能反过来。