Skip to content

Commit f4a509c

Browse files
jwakelyzygoloid
authored andcommitted
P0458R2 Checking for Existence of an Element in Associative Containers
[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.
1 parent b3f2432 commit f4a509c

File tree

1 file changed

+50
-3
lines changed

1 file changed

+50
-3
lines changed

source/containers.tex

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,6 +1620,15 @@
16201620
\tcode{m} denotes an allocator of a type convertible to \tcode{A},
16211621
and \tcode{nh} denotes a non-const rvalue of type \tcode{X::node_type}.
16221622

1623+
% Local command to index names as members of all ordered containers.
1624+
\newcommand{\indexordmem}[1]{%
1625+
\indexlibrary{\idxcode{#1}!ordered associative containers}%
1626+
\indexlibrary{\idxcode{set}!\idxcode{#1}}%
1627+
\indexlibrary{\idxcode{map}!\idxcode{#1}}%
1628+
\indexlibrary{\idxcode{multiset}!\idxcode{#1}}%
1629+
\indexlibrary{\idxcode{multimap}!\idxcode{#1}}%
1630+
}
1631+
16231632
\begin{libreqtab4b}
16241633
{Associative container requirements (in addition to container)}
16251634
{tab:containers.associative.requirements}
@@ -1948,6 +1957,19 @@
19481957
\tcode{!c(r, ke) \&\& !c(ke, r)} &
19491958
$\log (\tcode{a_tran.size()}) + \tcode{a_tran.count(ke)}$ \\ \rowsep
19501959

1960+
\indexordmem{contains}%
1961+
\tcode{b.}\br
1962+
\tcode{contains(k)} &
1963+
\tcode{bool} &
1964+
equivalent to \tcode{b.find(k) != b.end()} &
1965+
logarithmic \\ \rowsep
1966+
1967+
\tcode{a_tran.}\br
1968+
\tcode{con\-tains(ke)} &
1969+
\tcode{bool} &
1970+
equivalent to \tcode{a_tran.find(ke) != a_tran.end()} &
1971+
logarithmic \\ \rowsep
1972+
19511973
\tcode{b.lower_bound(k)} &
19521974
\tcode{iterator}; \tcode{const_iterator} for constant \tcode{b}. &
19531975
returns an iterator pointing to the first element with
@@ -2044,9 +2066,11 @@
20442066
its constructor.
20452067

20462068
\pnum
2047-
The member function templates \tcode{find}, \tcode{count}, \tcode{lower_bound},
2048-
\tcode{upper_bound}, and \tcode{equal_range} shall not participate in overload
2049-
resolution unless the \grammarterm{qualified-id} \tcode{Compare::is_transparent} is valid
2069+
The member function templates
2070+
\tcode{find}, \tcode{count}, \tcode{contains},
2071+
\tcode{lower_bound}, \tcode{upper_bound}, and \tcode{equal_range}
2072+
shall not participate in overload resolution unless
2073+
the \grammarterm{qualified-id} \tcode{Compare::is_transparent} is valid
20502074
and denotes a type\iref{temp.deduct}.
20512075

20522076
\pnum
@@ -2672,6 +2696,13 @@
26722696
& Average case \bigoh{\tcode{b.count(k)}}, worst case \bigoh{\tcode{b.size()}}.
26732697
\\ \rowsep
26742698
%
2699+
\indexunordmem{contains}%
2700+
\tcode{b.contains(k)}
2701+
& \tcode{bool}
2702+
& Equivalent to \tcode{b.find(k) != b.end()}%
2703+
& Average case \bigoh{1}, worst case \bigoh{\tcode{b.size()}}.
2704+
\\ \rowsep
2705+
%
26752706
\indexunordmem{equal_range}%
26762707
\tcode{b.equal_range(k)}
26772708
& \tcode{pair<iterator, iterator>}; \br
@@ -6104,6 +6135,9 @@
61046135
size_type count(const key_type& x) const;
61056136
template<class K> size_type count(const K& x) const;
61066137

6138+
bool contains(const key_type& x) const;
6139+
template<class K> bool contains(const K& x) const;
6140+
61076141
iterator lower_bound(const key_type& x);
61086142
const_iterator lower_bound(const key_type& x) const;
61096143
template<class K> iterator lower_bound(const K& x);
@@ -6596,6 +6630,9 @@
65966630
size_type count(const key_type& x) const;
65976631
template<class K> size_type count(const K& x) const;
65986632

6633+
bool contains(const key_type& x) const;
6634+
template<class K> bool contains(const K& x) const;
6635+
65996636
iterator lower_bound(const key_type& x);
66006637
const_iterator lower_bound(const key_type& x) const;
66016638
template<class K> iterator lower_bound(const K& x);
@@ -6875,6 +6912,9 @@
68756912
size_type count(const key_type& x) const;
68766913
template<class K> size_type count(const K& x) const;
68776914

6915+
bool contains(const key_type& x) const;
6916+
template<class K> bool contains(const K& x) const;
6917+
68786918
iterator lower_bound(const key_type& x);
68796919
const_iterator lower_bound(const key_type& x) const;
68806920
template<class K> iterator lower_bound(const K& x);
@@ -7126,6 +7166,9 @@
71267166
size_type count(const key_type& x) const;
71277167
template<class K> size_type count(const K& x) const;
71287168

7169+
bool contains(const key_type& x) const;
7170+
template<class K> bool contains(const K& x) const;
7171+
71297172
iterator lower_bound(const key_type& x);
71307173
const_iterator lower_bound(const key_type& x) const;
71317174
template<class K> iterator lower_bound(const K& x);
@@ -7536,6 +7579,7 @@
75367579
iterator find(const key_type& k);
75377580
const_iterator find(const key_type& k) const;
75387581
size_type count(const key_type& k) const;
7582+
bool contains(const key_type& k) const;
75397583
pair<iterator, iterator> equal_range(const key_type& k);
75407584
pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
75417585

@@ -8064,6 +8108,7 @@
80648108
iterator find(const key_type& k);
80658109
const_iterator find(const key_type& k) const;
80668110
size_type count(const key_type& k) const;
8111+
bool contains(const key_type& k) const;
80678112
pair<iterator, iterator> equal_range(const key_type& k);
80688113
pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
80698114

@@ -8390,6 +8435,7 @@
83908435
iterator find(const key_type& k);
83918436
const_iterator find(const key_type& k) const;
83928437
size_type count(const key_type& k) const;
8438+
bool contains(const key_type& k) const;
83938439
pair<iterator, iterator> equal_range(const key_type& k);
83948440
pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
83958441

@@ -8678,6 +8724,7 @@
86788724
iterator find(const key_type& k);
86798725
const_iterator find(const key_type& k) const;
86808726
size_type count(const key_type& k) const;
8727+
bool contains(const key_type& k) const;
86818728
pair<iterator, iterator> equal_range(const key_type& k);
86828729
pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
86838730

0 commit comments

Comments
 (0)