新的 std::map::erase() 签名 C++17
New std::map::erase() signature C++17
根据, an iterator
must be implicitly convertible to const_iterator
. Since that is true, as we can see happening in insert_or_assign()
, then why in C++17 was a new signature added to std::map::erase()
?
在 C++11 中,我们有 iterator erase( const_iterator pos );
在 C++17 中,我们现在有 iterator erase( iterator pos );
C++11 签名是否足以接收 iterator
和 const_iterator
?
当您传递 iterator
时,erase(const key_type& key)
可能存在歧义。考虑 key_type
类似于 std::any
.
的情况
根据iterator
must be implicitly convertible to const_iterator
. Since that is true, as we can see happening in insert_or_assign()
, then why in C++17 was a new signature added to std::map::erase()
?
在 C++11 中,我们有 iterator erase( const_iterator pos );
在 C++17 中,我们现在有 iterator erase( iterator pos );
C++11 签名是否足以接收 iterator
和 const_iterator
?
当您传递 iterator
时,erase(const key_type& key)
可能存在歧义。考虑 key_type
类似于 std::any
.