diff options
| author | Wim Leflere <wim.leflere@gmail.com> | 2021-01-19 14:33:30 -0500 |
|---|---|---|
| committer | Louis Dionne <ldionne.2@gmail.com> | 2021-01-19 14:35:07 -0500 |
| commit | 6ac9cb2a7c6c19797fc778f3d441a6fb7b69793c (patch) | |
| tree | 9f9dead4611ca9e64b9cf36c4a942063b0c297c9 /libcxx/test/std/strings/string.view/string.view.template/contains.char.pass.cpp | |
| parent | 7113de301a846521a2bdd73d44ac9cf5827b37a6 (diff) | |
[libc++][P1679] add string contains
C++23 string contains implementation and tests
Paper: https://wg21.link/P1679R3
Standard (string): https://eel.is/c++draft/string.contains
Standard (string_view): https://eel.is/c++draft/string.view.ops#lib:contains,basic_string_view
Differential Revision: https://reviews.llvm.org/D93912
Diffstat (limited to 'libcxx/test/std/strings/string.view/string.view.template/contains.char.pass.cpp')
| -rw-r--r-- | libcxx/test/std/strings/string.view/string.view.template/contains.char.pass.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/libcxx/test/std/strings/string.view/string.view.template/contains.char.pass.cpp b/libcxx/test/std/strings/string.view/string.view.template/contains.char.pass.cpp new file mode 100644 index 000000000000..658e10d21182 --- /dev/null +++ b/libcxx/test/std/strings/string.view/string.view.template/contains.char.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17, c++2a + +// <string_view> + +// constexpr bool contains(charT x) const noexcept; + +#include <string_view> +#include <cassert> + +#include "test_macros.h" + +constexpr bool test() +{ + using SV = std::string_view; + + SV sv1 {}; + SV sv2 {"abcde", 5}; + + ASSERT_NOEXCEPT(sv1.contains('e')); + + assert(!sv1.contains('c')); + assert(!sv1.contains('e')); + assert(!sv1.contains('x')); + assert( sv2.contains('c')); + assert( sv2.contains('e')); + assert(!sv2.contains('x')); + + return true; +} + +int main(int, char**) +{ + test(); + static_assert(test()); + + return 0; +} |
