1053d81ceSMarshall Clow //===----------------------------------------------------------------------===//
2053d81ceSMarshall Clow //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6053d81ceSMarshall Clow //
7053d81ceSMarshall Clow //===----------------------------------------------------------------------===//
8053d81ceSMarshall Clow 
9*4fc50236SJoe Loser // UNSUPPORTED: !stdlib=libc++ && (c++03 || c++11 || c++14)
10*4fc50236SJoe Loser 
11053d81ceSMarshall Clow // <string_view>
12053d81ceSMarshall Clow 
13053d81ceSMarshall Clow // const_iterator rbegin() const;
14053d81ceSMarshall Clow 
15053d81ceSMarshall Clow #include <string_view>
16053d81ceSMarshall Clow #include <cassert>
17053d81ceSMarshall Clow 
18053d81ceSMarshall Clow #include "test_macros.h"
19053d81ceSMarshall Clow 
20053d81ceSMarshall Clow template <class S>
21053d81ceSMarshall Clow void
test(S s)22053d81ceSMarshall Clow test(S s)
23053d81ceSMarshall Clow {
24053d81ceSMarshall Clow     const S& cs = s;
25053d81ceSMarshall Clow     typename S::reverse_iterator b = s.rbegin();
26053d81ceSMarshall Clow     typename S::const_reverse_iterator cb1 = cs.rbegin();
27053d81ceSMarshall Clow     typename S::const_reverse_iterator cb2 = s.crbegin();
28053d81ceSMarshall Clow     if (!s.empty())
29053d81ceSMarshall Clow     {
30053d81ceSMarshall Clow         const size_t last = s.size() - 1;
31053d81ceSMarshall Clow         assert(   *b ==  s[last]);
32053d81ceSMarshall Clow         assert(  &*b == &s[last]);
33053d81ceSMarshall Clow         assert( *cb1 ==  s[last]);
34053d81ceSMarshall Clow         assert(&*cb1 == &s[last]);
35053d81ceSMarshall Clow         assert( *cb2 ==  s[last]);
36053d81ceSMarshall Clow         assert(&*cb2 == &s[last]);
37053d81ceSMarshall Clow 
38053d81ceSMarshall Clow     }
39053d81ceSMarshall Clow     assert(  b == cb1);
40053d81ceSMarshall Clow     assert(  b == cb2);
41053d81ceSMarshall Clow     assert(cb1 == cb2);
42053d81ceSMarshall Clow }
43053d81ceSMarshall Clow 
44053d81ceSMarshall Clow 
main(int,char **)452df59c50SJF Bastien int main(int, char**)
46053d81ceSMarshall Clow {
47053d81ceSMarshall Clow     typedef std::string_view    string_view;
487dad0bd6SMarshall Clow #if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L
497dad0bd6SMarshall Clow     typedef std::u8string_view  u8string_view;
507dad0bd6SMarshall Clow #endif
51053d81ceSMarshall Clow     typedef std::u16string_view u16string_view;
52053d81ceSMarshall Clow     typedef std::u32string_view u32string_view;
53053d81ceSMarshall Clow 
54053d81ceSMarshall Clow     test(string_view   ());
55053d81ceSMarshall Clow     test(u16string_view());
56053d81ceSMarshall Clow     test(u32string_view());
57053d81ceSMarshall Clow     test(string_view   ( "123"));
587dad0bd6SMarshall Clow #if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L
597dad0bd6SMarshall Clow     test(u8string_view{u8"123"});
607dad0bd6SMarshall Clow #endif
61053d81ceSMarshall Clow #if TEST_STD_VER >= 11
62053d81ceSMarshall Clow     test(u16string_view{u"123"});
63053d81ceSMarshall Clow     test(u32string_view{U"123"});
64053d81ceSMarshall Clow #endif
65f56e3cddSMarshall Clow 
66f4c1258dSLouis Dionne #ifndef TEST_HAS_NO_WIDE_CHARACTERS
67f4c1258dSLouis Dionne     typedef std::wstring_view   wstring_view;
68f4c1258dSLouis Dionne     test(wstring_view  ());
69f4c1258dSLouis Dionne     test(wstring_view  (L"123"));
70f4c1258dSLouis Dionne #endif
71f4c1258dSLouis Dionne 
72f56e3cddSMarshall Clow #if TEST_STD_VER > 14
73f56e3cddSMarshall Clow     {
74f56e3cddSMarshall Clow     constexpr string_view       sv { "123", 3 };
757dad0bd6SMarshall Clow #if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L
767dad0bd6SMarshall Clow     constexpr u8string_view u8sv  {u8"123", 3 };
777dad0bd6SMarshall Clow #endif
78f56e3cddSMarshall Clow     constexpr u16string_view u16sv {u"123", 3 };
79f56e3cddSMarshall Clow     constexpr u32string_view u32sv {U"123", 3 };
80f56e3cddSMarshall Clow 
81f56e3cddSMarshall Clow     static_assert (    *sv.rbegin() ==    sv[2], "" );
827dad0bd6SMarshall Clow #if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L
837dad0bd6SMarshall Clow     static_assert (  *u8sv.rbegin() ==  u8sv[2], "" );
847dad0bd6SMarshall Clow #endif
85f56e3cddSMarshall Clow     static_assert ( *u16sv.rbegin() == u16sv[2], "" );
86f56e3cddSMarshall Clow     static_assert ( *u32sv.rbegin() == u32sv[2], "" );
87f56e3cddSMarshall Clow 
88f56e3cddSMarshall Clow     static_assert (    *sv.crbegin() ==    sv[2], "" );
897dad0bd6SMarshall Clow #if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L
907dad0bd6SMarshall Clow     static_assert (  *u8sv.crbegin() == u8sv[2], "" );
917dad0bd6SMarshall Clow #endif
92f56e3cddSMarshall Clow     static_assert ( *u16sv.crbegin() == u16sv[2], "" );
93f56e3cddSMarshall Clow     static_assert ( *u32sv.crbegin() == u32sv[2], "" );
94f4c1258dSLouis Dionne 
95f4c1258dSLouis Dionne #ifndef TEST_HAS_NO_WIDE_CHARACTERS
96f4c1258dSLouis Dionne         {
97f4c1258dSLouis Dionne             constexpr wstring_view     wsv {L"123", 3 };
98f4c1258dSLouis Dionne             static_assert (   *wsv.rbegin() ==   wsv[2], "" );
99f56e3cddSMarshall Clow             static_assert (   *wsv.crbegin() ==   wsv[2], "" );
100f56e3cddSMarshall Clow         }
101f56e3cddSMarshall Clow #endif
102f4c1258dSLouis Dionne     }
103f4c1258dSLouis Dionne #endif // TEST_STD_VER > 14
1042df59c50SJF Bastien 
1052df59c50SJF Bastien   return 0;
106053d81ceSMarshall Clow }
107