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 // const_iterator rbegin() const;
13 #include <string_view>
16 #include "test_macros.h"
23 typename
S::reverse_iterator b
= s
.rbegin();
24 typename
S::const_reverse_iterator cb1
= cs
.rbegin();
25 typename
S::const_reverse_iterator cb2
= s
.crbegin();
28 const size_t last
= s
.size() - 1;
29 assert( *b
== s
[last
]);
30 assert( &*b
== &s
[last
]);
31 assert( *cb1
== s
[last
]);
32 assert(&*cb1
== &s
[last
]);
33 assert( *cb2
== s
[last
]);
34 assert(&*cb2
== &s
[last
]);
45 typedef std::string_view string_view
;
46 #if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L
47 typedef std::u8string_view u8string_view
;
49 typedef std::u16string_view u16string_view
;
50 typedef std::u32string_view u32string_view
;
51 typedef std::wstring_view wstring_view
;
54 test(u16string_view());
55 test(u32string_view());
56 test(wstring_view ());
57 test(string_view ( "123"));
58 test(wstring_view (L
"123"));
59 #if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L
60 test(u8string_view
{u8
"123"});
62 #if TEST_STD_VER >= 11
63 test(u16string_view
{u
"123"});
64 test(u32string_view
{U
"123"});
69 constexpr string_view sv
{ "123", 3 };
70 #if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L
71 constexpr u8string_view u8sv
{u8
"123", 3 };
73 constexpr u16string_view u16sv
{u
"123", 3 };
74 constexpr u32string_view u32sv
{U
"123", 3 };
75 constexpr wstring_view wsv
{L
"123", 3 };
77 static_assert ( *sv
.rbegin() == sv
[2], "" );
78 #if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L
79 static_assert ( *u8sv
.rbegin() == u8sv
[2], "" );
81 static_assert ( *u16sv
.rbegin() == u16sv
[2], "" );
82 static_assert ( *u32sv
.rbegin() == u32sv
[2], "" );
83 static_assert ( *wsv
.rbegin() == wsv
[2], "" );
85 static_assert ( *sv
.crbegin() == sv
[2], "" );
86 #if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L
87 static_assert ( *u8sv
.crbegin() == u8sv
[2], "" );
89 static_assert ( *u16sv
.crbegin() == u16sv
[2], "" );
90 static_assert ( *u32sv
.crbegin() == u32sv
[2], "" );
91 static_assert ( *wsv
.crbegin() == wsv
[2], "" );