d: Merge dmd, druntime c7902293d7, phobos 03aeafd20
[gcc.git] / libstdc++-v3 / testsuite / 25_algorithms / search_n / 97828.cc
blob50594ac46b8ad4d3cfb8c9af498681c24fb31881
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.
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++20 } }
20 // PR libstdc++/97828
22 #include <algorithm>
23 #include <testsuite_hooks.h>
24 #include <testsuite_iterators.h>
26 using __gnu_test::test_sized_range;
27 using __gnu_test::forward_iterator_wrapper;
28 using __gnu_test::random_access_iterator_wrapper;
30 template<template<typename> typename Wrapper>
31 void
32 test01()
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 );
40 template<template<typename> typename Wrapper>
41 void
42 test02()
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 );
50 int
51 main()
53 test01<forward_iterator_wrapper>();
54 test01<random_access_iterator_wrapper>();
55 test02<forward_iterator_wrapper>();
56 test02<random_access_iterator_wrapper>();