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 #include "min_allocator.h"
     21 
     22 int main()
     23 {
     24     {
     25         typedef int T;
     26         typedef std::forward_list<T> C;
     27         C c;
     28         C::iterator i = c.before_begin();
     29         assert(std::distance(i, c.end()) == 1);
     30     }
     31     {
     32         typedef int T;
     33         typedef std::forward_list<T> C;
     34         const C c;
     35         C::const_iterator i = c.before_begin();
     36         assert(std::distance(i, c.end()) == 1);
     37     }
     38     {
     39         typedef int T;
     40         typedef std::forward_list<T> C;
     41         const C c;
     42         C::const_iterator i = c.cbefore_begin();
     43         assert(std::distance(i, c.end()) == 1);
     44         assert(c.cbefore_begin() == c.before_begin());
     45     }
     46     {
     47         typedef int T;
     48         typedef std::forward_list<T> C;
     49         const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
     50         C c(std::begin(t), std::end(t));
     51         C::iterator i = c.before_begin();
     52         assert(std::distance(i, c.end()) == 11);
     53         assert(std::next(c.before_begin()) == c.begin());
     54     }
     55     {
     56         typedef int T;
     57         typedef std::forward_list<T> C;
     58         const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
     59         const C c(std::begin(t), std::end(t));
     60         C::const_iterator i = c.before_begin();
     61         assert(std::distance(i, c.end()) == 11);
     62     }
     63 #if __cplusplus >= 201103L
     64     {
     65         typedef int T;
     66         typedef std::forward_list<T, min_allocator<T>> C;
     67         C c;
     68         C::iterator i = c.before_begin();
     69         assert(std::distance(i, c.end()) == 1);
     70     }
     71     {
     72         typedef int T;
     73         typedef std::forward_list<T, min_allocator<T>> C;
     74         const C c;
     75         C::const_iterator i = c.before_begin();
     76         assert(std::distance(i, c.end()) == 1);
     77     }
     78     {
     79         typedef int T;
     80         typedef std::forward_list<T, min_allocator<T>> C;
     81         const C c;
     82         C::const_iterator i = c.cbefore_begin();
     83         assert(std::distance(i, c.end()) == 1);
     84         assert(c.cbefore_begin() == c.before_begin());
     85     }
     86     {
     87         typedef int T;
     88         typedef std::forward_list<T, min_allocator<T>> C;
     89         const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
     90         C c(std::begin(t), std::end(t));
     91         C::iterator i = c.before_begin();
     92         assert(std::distance(i, c.end()) == 11);
     93         assert(std::next(c.before_begin()) == c.begin());
     94     }
     95     {
     96         typedef int T;
     97         typedef std::forward_list<T, min_allocator<T>> C;
     98         const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
     99         const C c(std::begin(t), std::end(t));
    100         C::const_iterator i = c.before_begin();
    101         assert(std::distance(i, c.end()) == 11);
    102     }
    103 #endif
    104 }
    105