Skip to content
New issue

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

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

Open
dcstempt opened this issue Feb 22, 2023 · 1 comment

Comments

@dcstempt
Copy link

dcstempt commented Feb 22, 2023


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

@frederick-vs-ja
Copy link
Contributor

frederick-vs-ja commented Oct 10, 2023

实际的 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> 而不能反过来。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants