| 1 | // Copyright (C) 2019-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 compile { target c++20 } } |
| 19 | |
| 20 | #include <functional> |
| 21 | |
| 22 | #ifndef __cpp_lib_constexpr_functional |
| 23 | # error "Feature test macro for constexpr searcher is missing in <functional>" |
| 24 | #elif __cpp_lib_constexpr_functional < 201811L |
| 25 | # error "Feature test macro for constexpr searcher has wrong value in <functional>" |
| 26 | #endif |
| 27 | |
| 28 | #include <string_view> |
| 29 | |
| 30 | constexpr std::string_view |
| 31 | patt = "World"; |
| 32 | |
| 33 | constexpr std::string_view |
| 34 | greet = "Hello, Humongous World of Wonder!!!"; |
| 35 | |
| 36 | constexpr std::wstring_view |
| 37 | wpatt = L"World"; |
| 38 | |
| 39 | constexpr std::wstring_view |
| 40 | wgreet = L"Hello, Humongous World of Wonder!!!"; |
| 41 | |
| 42 | constexpr bool |
| 43 | test_searcher() |
| 44 | { |
| 45 | auto ok = true; |
| 46 | |
| 47 | const std::default_searcher search(patt.begin(), patt.end(), |
| 48 | std::equal_to<>()); |
| 49 | const auto find = search(greet.begin(), greet.end()); |
| 50 | |
| 51 | const std::default_searcher wsearch(wpatt.begin(), wpatt.end(), |
| 52 | std::equal_to<>()); |
| 53 | const auto wfind = wsearch(wgreet.begin(), wgreet.end()); |
| 54 | |
| 55 | return ok; |
| 56 | } |
| 57 | |
| 58 | static_assert(test_searcher()); |