1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
11 // constexpr const _CharT& at(size_type _pos) const;
13 #include <string_view>
17 #include "test_macros.h"
19 template <typename CharT
>
20 void test(const CharT
* s
, std::size_t len
) {
21 std::basic_string_view
<CharT
> sv(s
, len
);
22 assert(sv
.length() == len
);
23 for (std::size_t i
= 0; i
< len
; ++i
) {
24 assert(sv
.at(i
) == s
[i
]);
25 assert(&sv
.at(i
) == s
+ i
);
28 #ifndef TEST_HAS_NO_EXCEPTIONS
31 } catch (const std::out_of_range
&) {
38 int main(int, char**) {
42 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
47 #if TEST_STD_VER >= 11
55 #if TEST_STD_VER >= 11
57 constexpr std::basic_string_view
<char> sv("ABC", 2);
58 static_assert(sv
.length() == 2, "");
59 static_assert(sv
.at(0) == 'A', "");
60 static_assert(sv
.at(1) == 'B', "");