Home | History | Annotate | Download | only in forwardlist.iter
      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 // <forward_list>
     11 
     12 // iterator       before_begin();
     13 // const_iterator before_begin() const;
     14 // const_iterator cbefore_begin() const;
     15 
     16 #include <forward_list>
     17 #include <cassert>
     18 #include <iterator>
     19 
     20 int main()
     21 {
     22     {
     23         typedef int T;
     24         typedef std::forward_list<T> C;
     25         C c;
     26         C::iterator i = c.before_begin();
     27         assert(std::distance(i, c.end()) == 1);
     28     }
     29     {
     30         typedef int T;
     31         typedef std::forward_list<T> C;
     32         const C c;
     33         C::const_iterator i = c.before_begin();
     34         assert(std::distance(i, c.end()) == 1);
     35     }
     36     {
     37         typedef int T;
     38         typedef std::forward_list<T> C;
     39         const C c;
     40         C::const_iterator i = c.cbefore_begin();
     41         assert(std::distance(i, c.end()) == 1);
     42         assert(c.cbefore_begin() == c.before_begin());
     43     }
     44     {
     45         typedef int T;
     46         typedef std::forward_list<T> C;
     47         const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
     48         C c(std::begin(t), std::end(t));
     49         C::iterator i = c.before_begin();
     50         assert(std::distance(i, c.end()) == 11);
     51         assert(std::next(c.before_begin()) == c.begin());
     52     }
     53     {
     54         typedef int T;
     55         typedef std::forward_list<T> C;
     56         const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
     57         const C c(std::begin(t), std::end(t));
     58         C::const_iterator i = c.before_begin();
     59         assert(std::distance(i, c.end()) == 11);
     60     }
     61 }
     62