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 // constexpr const_iterator rend() const; 13 14 #include <experimental/string_view> 15 #include <cassert> 16 17 template <class S> 18 void 19 test(S s) 20 { 21 const S& cs = s; 22 typename S::reverse_iterator e = s.rend(); 23 typename S::const_reverse_iterator ce1 = cs.rend(); 24 typename S::const_reverse_iterator ce2 = s.crend(); 25 26 if (s.empty()) 27 { 28 assert( e == s.rbegin()); 29 assert(ce1 == cs.rbegin()); 30 assert(ce2 == s.rbegin()); 31 } 32 else 33 { 34 assert( e != s.rbegin()); 35 assert(ce1 != cs.rbegin()); 36 assert(ce2 != s.rbegin()); 37 } 38 39 assert( e - s.rbegin() == s.size()); 40 assert(ce1 - cs.rbegin() == cs.size()); 41 assert(ce2 - s.crbegin() == s.size()); 42 43 assert( e == ce1); 44 assert( e == ce2); 45 assert(ce1 == ce2); 46 } 47 48 49 int main() 50 { 51 typedef std::experimental::string_view string_view; 52 typedef std::experimental::u16string_view u16string_view; 53 typedef std::experimental::u32string_view u32string_view; 54 typedef std::experimental::wstring_view wstring_view; 55 56 test(string_view ()); 57 test(u16string_view()); 58 test(u32string_view()); 59 test(wstring_view ()); 60 test(string_view ( "123")); 61 test(wstring_view (L"123")); 62 #if __cplusplus >= 201103L 63 test(u16string_view{u"123"}); 64 test(u32string_view{U"123"}); 65 #endif 66 } 67