]>
Commit | Line | Data |
---|---|---|
c5ae1a27 JW |
1 | // Copyright (C) 2017 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-options "-std=gnu++17" } | |
19 | // { dg-do compile { target c++1z } } | |
20 | ||
21 | #include <string_view> | |
22 | ||
23 | struct constexpr_char_traits : std::char_traits<char> | |
24 | { | |
25 | static constexpr size_t | |
26 | length(const char* val) | |
27 | { | |
28 | size_t res = 0; | |
29 | for (; val[res] != '\0'; ++res) | |
30 | ; | |
31 | return res; | |
32 | } | |
33 | ||
34 | static constexpr int | |
35 | compare(const char* lhs, const char* rhs, std::size_t count) | |
36 | { | |
37 | for (size_t pos = 0; pos < count; ++pos) | |
38 | { | |
39 | if (lhs[pos] != rhs[pos]) | |
40 | return lhs[pos] - rhs[pos]; | |
41 | } | |
42 | return 0; | |
43 | } | |
44 | }; | |
45 | ||
46 | using string_view = std::basic_string_view<char, constexpr_char_traits>; | |
47 | ||
48 | constexpr | |
49 | string_view get() | |
50 | { | |
51 | string_view res = "x::"; | |
52 | string_view start_pattern = "x"; | |
53 | res = res.substr(res.find(start_pattern) + start_pattern.size()); | |
54 | res = res.substr(0, res.find_first_of(";]")); | |
55 | res = res.substr(res.rfind("::")); | |
56 | return res; | |
57 | } | |
58 | ||
59 | static_assert( get() == get() ); | |
60 | ||
61 | using std::u16string_view; | |
62 | ||
63 | constexpr | |
64 | u16string_view get16() | |
65 | { | |
66 | u16string_view res = u"x::"; | |
67 | u16string_view start_pattern = u"x"; | |
68 | res = res.substr(res.find(start_pattern) + start_pattern.size()); | |
69 | res = res.substr(0, res.find_first_of(u";]")); | |
70 | res = res.substr(res.rfind(u"::")); | |
71 | return res; | |
72 | } | |
73 | ||
74 | static_assert( get16() == get16() ); | |
75 | ||
76 | using std::u32string_view; | |
77 | ||
78 | constexpr | |
79 | u32string_view get32() | |
80 | { | |
81 | u32string_view res = U"x::"; | |
82 | u32string_view start_pattern = U"x"; | |
83 | res = res.substr(res.find(start_pattern) + start_pattern.size()); | |
84 | res = res.substr(0, res.find_first_of(U";]")); | |
85 | res = res.substr(res.rfind(U"::")); | |
86 | return res; | |
87 | } | |
88 | ||
89 | static_assert( get32() == get32() ); |