]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/23_containers/set/operations/2.cc
1 // Copyright (C) 2015-2017 Free Software Foundation, Inc.
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // { dg-do run { target c++14 } }
21 #include <testsuite_hooks.h>
25 typedef void is_transparent
;
27 bool operator()(int i
, long l
) const { return i
< l
; }
28 bool operator()(long l
, int i
) const { return l
< i
; }
29 bool operator()(int i
, int j
) const { ++count
; return i
< j
; }
36 using test_type
= std::set
<int, Cmp
>;
38 test_type x
{ 1, 3, 5 };
39 const test_type
& cx
= x
;
47 VERIFY( it
!= x
.end() && *it
== 1 );
49 VERIFY( it
== x
.end() );
51 auto cit
= cx
.find(3L);
52 VERIFY( cit
!= cx
.end() && *cit
== 3 );
54 VERIFY( cit
== cx
.end() );
56 VERIFY( Cmp::count
== 0);
58 static_assert(std::is_same
<decltype(it
), test_type::iterator
>::value
,
59 "find returns iterator");
60 static_assert(std::is_same
<decltype(cit
), test_type::const_iterator
>::value
,
61 "const find returns const_iterator");
74 auto cn
= cx
.count(3L);
79 VERIFY( Cmp::count
== 0);
87 auto it
= x
.lower_bound(1L);
88 VERIFY( it
!= x
.end() && *it
== 1 );
89 it
= x
.lower_bound(2L);
90 VERIFY( it
!= x
.end() && *it
== 3 );
92 auto cit
= cx
.lower_bound(1L);
93 VERIFY( cit
!= cx
.end() && *cit
== 1 );
94 cit
= cx
.lower_bound(2L);
95 VERIFY( cit
!= cx
.end() && *cit
== 3 );
97 VERIFY( Cmp::count
== 0);
105 auto it
= x
.upper_bound(1L);
106 VERIFY( it
!= x
.end() && *it
== 3 );
107 it
= x
.upper_bound(5L);
108 VERIFY( it
== x
.end() );
110 auto cit
= cx
.upper_bound(1L);
111 VERIFY( cit
!= cx
.end() && *cit
== 3 );
112 cit
= cx
.upper_bound(5L);
113 VERIFY( cit
== cx
.end() );
115 VERIFY( Cmp::count
== 0);
123 auto it
= x
.equal_range(1L);
124 VERIFY( it
.first
!= it
.second
&& *it
.first
== 1 );
125 it
= x
.equal_range(2L);
126 VERIFY( it
.first
== it
.second
&& it
.first
!= x
.end() );
128 auto cit
= cx
.equal_range(1L);
129 VERIFY( cit
.first
!= cit
.second
&& *cit
.first
== 1 );
130 cit
= cx
.equal_range(2L);
131 VERIFY( cit
.first
== cit
.second
&& cit
.first
!= cx
.end() );
133 VERIFY( Cmp::count
== 0);
139 // https://gcc.gnu.org/ml/libstdc++/2015-01/msg00176.html
140 // Verify the new function template overloads do not cause problems
141 // when the comparison function is not transparent.
145 operator int() const { return i
; }