Home | History | Annotate | Download | only in string.view.iterators
      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 template <class S>
     18 void
     19 test(S s)
     20 {
     21     const S& cs = s;
     22     typename S::reverse_iterator b = s.rbegin();
     23     typename S::const_reverse_iterator cb1 = cs.rbegin();
     24     typename S::const_reverse_iterator cb2 = s.crbegin();
     25     if (!s.empty())
     26     {
     27         const size_t last = s.size() - 1;
     28         assert(   *b ==  s[last]);
     29         assert(  &*b == &s[last]);
     30         assert( *cb1 ==  s[last]);
     31         assert(&*cb1 == &s[last]);
     32         assert( *cb2 ==  s[last]);
     33         assert(&*cb2 == &s[last]);
     34 
     35     }
     36     assert(  b == cb1);
     37     assert(  b == cb2);
     38     assert(cb1 == cb2);
     39 }
     40 
     41 
     42 int main()
     43 {
     44     typedef std::experimental::string_view    string_view;
     45     typedef std::experimental::u16string_view u16string_view;
     46     typedef std::experimental::u32string_view u32string_view;
     47     typedef std::experimental::wstring_view   wstring_view;
     48 
     49     test(string_view   ());
     50     test(u16string_view());
     51     test(u32string_view());
     52     test(wstring_view  ());
     53     test(string_view   ( "123"));
     54     test(wstring_view  (L"123"));
     55 #if __cplusplus >= 201103L
     56     test(u16string_view{u"123"});
     57     test(u32string_view{U"123"});
     58 #endif
     59 }
     60