Home | History | Annotate | Download | only in forwardlist.cons
      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 // explicit forward_list(size_type n);
     13 // explicit forward_list(size_type n, const Alloc& a);
     14 
     15 #include <forward_list>
     16 #include <cassert>
     17 
     18 #include "DefaultOnly.h"
     19 #include "min_allocator.h"
     20 
     21 template <class T, class Allocator>
     22 void check_allocator(unsigned n, Allocator const &alloc = Allocator())
     23 {
     24 #if _LIBCPP_STD_VER > 11
     25     typedef std::forward_list<T, Allocator> C;
     26     C d(n, alloc);
     27     assert(d.get_allocator() == alloc);
     28     assert(std::distance(d.begin(), d.end()) == n);
     29 #endif
     30 }
     31 
     32 int main()
     33 {
     34     {
     35         typedef DefaultOnly T;
     36         typedef std::forward_list<T> C;
     37         unsigned N = 10;
     38         C c(N);
     39         unsigned n = 0;
     40         for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n)
     41 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     42             assert(*i == T());
     43 #else
     44             ;
     45 #endif
     46         assert(n == N);
     47     }
     48 #if __cplusplus >= 201103L
     49     {
     50         typedef DefaultOnly T;
     51         typedef std::forward_list<T, min_allocator<T>> C;
     52         unsigned N = 10;
     53         C c(N);
     54         unsigned n = 0;
     55         for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n)
     56 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     57             assert(*i == T());
     58 #else
     59             ;
     60 #endif
     61         assert(n == N);
     62         check_allocator<T, min_allocator<T>> ( 0 );
     63         check_allocator<T, min_allocator<T>> ( 3 );
     64     }
     65 #endif
     66 }
     67