1 // Copyright (C) 2017-2023 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-do compile { target c++14 } }
20 #include <experimental/string_view>
22 struct constexpr_char_traits
: std::char_traits
<char>
24 static constexpr size_t
25 length(const char* val
)
28 for (; val
[res
] != '\0'; ++res
)
34 compare(const char* lhs
, const char* rhs
, std::size_t count
)
36 for (size_t pos
= 0; pos
< count
; ++pos
)
38 if (lhs
[pos
] != rhs
[pos
])
39 return lhs
[pos
] - rhs
[pos
];
44 static constexpr const char*
45 find(const char* p
, std::size_t n
, char c
)
47 for (size_t pos
= 0; pos
< n
; ++pos
)
55 = std::experimental::basic_string_view
<char, constexpr_char_traits
>;
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("::"));
68 static_assert( get() == get() );