1 // Copyright (C) 2017-2019 Free Software Foundation, Inc.
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)
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-options "-std=gnu++17" }
19 // { dg-do compile { target c++17 } }
21 #include <string_view>
23 struct constexpr_char_traits
: std::char_traits
<char>
25 static constexpr size_t
26 length(const char* val
)
29 for (; val
[res
] != '\0'; ++res
)
35 compare(const char* lhs
, const char* rhs
, std::size_t count
)
37 for (size_t pos
= 0; pos
< count
; ++pos
)
39 if (lhs
[pos
] != rhs
[pos
])
40 return lhs
[pos
] - rhs
[pos
];
46 using string_view
= std::basic_string_view
<char, constexpr_char_traits
>;
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("::"));
59 static_assert( get() == get() );
61 using std::u16string_view
;
64 u16string_view
get16()
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
"::"));
74 static_assert( get16() == get16() );
76 using std::u32string_view
;
79 u32string_view
get32()
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
"::"));
89 static_assert( get32() == get32() );