1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // <string_view> 11 12 // const_iterator rbegin() const; 13 14 #include <experimental/string_view> 15 #include <cassert> 16 17 #include "test_macros.h" 18 19 template <class S> 20 void 21 test(S s) 22 { 23 const S& cs = s; 24 typename S::reverse_iterator b = s.rbegin(); 25 typename S::const_reverse_iterator cb1 = cs.rbegin(); 26 typename S::const_reverse_iterator cb2 = s.crbegin(); 27 if (!s.empty()) 28 { 29 const size_t last = s.size() - 1; 30 assert( *b == s[last]); 31 assert( &*b == &s[last]); 32 assert( *cb1 == s[last]); 33 assert(&*cb1 == &s[last]); 34 assert( *cb2 == s[last]); 35 assert(&*cb2 == &s[last]); 36 37 } 38 assert( b == cb1); 39 assert( b == cb2); 40 assert(cb1 == cb2); 41 } 42 43 44 int main() 45 { 46 typedef std::experimental::string_view string_view; 47 typedef std::experimental::u16string_view u16string_view; 48 typedef std::experimental::u32string_view u32string_view; 49 typedef std::experimental::wstring_view wstring_view; 50 51 test(string_view ()); 52 test(u16string_view()); 53 test(u32string_view()); 54 test(wstring_view ()); 55 test(string_view ( "123")); 56 test(wstring_view (L"123")); 57 #if TEST_STD_VER >= 11 58 test(u16string_view{u"123"}); 59 test(u32string_view{U"123"}); 60 #endif 61 } 62