Debian Codegraph @

libstdc++-v3/testsuite/25_algorithms/search_n/97828.cc

raw
1 // Copyright (C) 2020-2025 Free Software Foundation, Inc.
2 //
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)
7 // any later version.
8
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.
13
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/>.
17
18 // { dg-do run { target c++20 } }
19
20 // PR libstdc++/97828
21
22 #include <algorithm>
23 #include <testsuite_hooks.h>
24 #include <testsuite_iterators.h>
25
26 using __gnu_test::test_sized_range;
27 using __gnu_test::forward_iterator_wrapper;
28 using __gnu_test::random_access_iterator_wrapper;
29
30 template<template<typename> typename Wrapper>
31 void
32 test01()
33 {
34 int x[] = {0,42,42,0,42,42,42};
35 test_sized_range<int, Wrapper> rx(x);
36 auto res = std::ranges::search_n(rx, 3, 42);
37 VERIFY( res.begin().ptr == x+4 && res.end().ptr == x+7 );
38 }
39
40 template<template<typename> typename Wrapper>
41 void
42 test02()
43 {
44 int x[] = {0,42,42,0,42};
45 test_sized_range<int, Wrapper> rx(x);
46 auto res = std::ranges::search_n(rx, 3, 42);
47 VERIFY( res.begin().ptr == x+5 && res.end().ptr == x+5 );
48 }
49
50 int
51 main()
52 {
53 test01<forward_iterator_wrapper>();
54 test01<random_access_iterator_wrapper>();
55 test02<forward_iterator_wrapper>();
56 test02<random_access_iterator_wrapper>();
57 }