-
Notifications
You must be signed in to change notification settings - Fork 769
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
P0458R2 Checking for existence of an element in associative containers #2163
Conversation
\tcode{con\-tains(ke)} & | ||
\tcode{bool} & | ||
equivalent to \tcode{a_tran.find(ke) != a_tran.end()} & | ||
logarithmic \\ \rowsep |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can do without the a_tran changes; since a_tran is a restriction of "b" and the semantics don't differ, we should be good. (The semantics of find() do differ, though, but that's hidden behind the function call.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So should it b b.contains(ke)
? Because otherwise we're only defining what happens if you call contains with the key type, and the transparent versions accept anything that can be compared to the key.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, that's the point.
Tell me more: We have these template <class K>
overloads all over the place; does that mean they're not active for non-transparent comparators?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But b.contains(ke)
doesn't necessarily work, it only works if b
has a transparent comparison function, in which case we'd use a_tran
.
I think we need both rows. The b
row is always valid, the a_tran
row (which isn't restricted to arguments convertible to key_type
) is only conditionally valid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does that mean they're not active for non-transparent comparators?
Yes, see [associative.reqmts] p14.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, so we need to edit p14 to add contains
!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After informing LWG of my intention, I've added contains
to p14 in a Fixup push to the branch.
source/containers.tex
Outdated
@@ -7536,6 +7567,7 @@ | |||
iterator find(const key_type& k); | |||
const_iterator find(const key_type& k) const; | |||
size_type count(const key_type& k) const; | |||
bool contains(const key_type& x) const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The key_type parameter name is called "k" in the vicinity. We should stay consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
source/containers.tex
Outdated
@@ -8064,6 +8096,7 @@ | |||
iterator find(const key_type& k); | |||
const_iterator find(const key_type& k) const; | |||
size_type count(const key_type& k) const; | |||
bool contains(const key_type& x) const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The key_type parameter name is called "k" in the vicinity. We should stay consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
source/containers.tex
Outdated
@@ -8390,6 +8423,7 @@ | |||
iterator find(const key_type& k); | |||
const_iterator find(const key_type& k) const; | |||
size_type count(const key_type& k) const; | |||
bool contains(const key_type& x) const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The key_type parameter name is called "k" in the vicinity. We should stay consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
source/containers.tex
Outdated
@@ -8678,6 +8712,7 @@ | |||
iterator find(const key_type& k); | |||
const_iterator find(const key_type& k) const; | |||
size_type count(const key_type& k) const; | |||
bool contains(const key_type& x) const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The key_type parameter name is called "k" in the vicinity. We should stay consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, thanks.
[associative.reqmts] Add "contains" to the list of member function templates that do not participate in overload resolution unless the comparator is transparent, as agreed on the lib reflector.
63c924f
to
f4a509c
Compare
Fixes #2133