]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/experimental/string_view/operations/compare/char/70483.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / experimental / string_view / operations / compare / char / 70483.cc
1 // Copyright (C) 2017-2020 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++14 } }
19
20 #include <experimental/string_view>
21
22 struct constexpr_char_traits : std::char_traits<char>
23 {
24 static constexpr size_t
25 length(const char* val)
26 {
27 size_t res = 0;
28 for (; val[res] != '\0'; ++res)
29 ;
30 return res;
31 }
32
33 static constexpr int
34 compare(const char* lhs, const char* rhs, std::size_t count)
35 {
36 for (size_t pos = 0; pos < count; ++pos)
37 {
38 if (lhs[pos] != rhs[pos])
39 return lhs[pos] - rhs[pos];
40 }
41 return 0;
42 }
43
44 static constexpr const char*
45 find(const char* p, std::size_t n, char c)
46 {
47 for (size_t pos = 0; pos < n; ++pos)
48 if (p[pos] == c)
49 return p + pos;
50 return nullptr;
51 }
52 };
53
54 using string_view
55 = std::experimental::basic_string_view<char, constexpr_char_traits>;
56
57 constexpr
58 string_view get()
59 {
60 string_view res = "x::";
61 string_view start_pattern = "x";
62 res = res.substr(res.find(start_pattern) + start_pattern.size());
63 res = res.substr(0, res.find_first_of(";]"));
64 res = res.substr(res.rfind("::"));
65 return res;
66 }
67
68 static_assert( get() == get() );