Home | History | Annotate | Download | only in forwardlist
      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 // template <class T, class Allocator = allocator<T>>
     13 // class forward_list
     14 // {
     15 // public:
     16 //   typedef T         value_type;
     17 //   typedef Allocator allocator_type;
     18 //
     19 //   typedef value_type&                                                reference;
     20 //   typedef const value_type&                                          const_reference;
     21 //   typedef typename allocator_traits<allocator_type>::pointer         pointer;
     22 //   typedef typename allocator_traits<allocator_type>::const_pointer   const_pointer;
     23 //   typedef typename allocator_traits<allocator_type>::size_type       size_type;
     24 //   typedef typename allocator_traits<allocator_type>::difference_type difference_type;
     25 //   ...
     26 // };
     27 
     28 #include <forward_list>
     29 #include <type_traits>
     30 
     31 #include "min_allocator.h"
     32 
     33 struct A { std::forward_list<A> v; }; // incomplete type support
     34 
     35 int main()
     36 {
     37     {
     38     typedef std::forward_list<char> C;
     39     static_assert((std::is_same<C::value_type, char>::value), "");
     40     static_assert((std::is_same<C::allocator_type, std::allocator<char> >::value), "");
     41     static_assert((std::is_same<C::reference, char&>::value), "");
     42     static_assert((std::is_same<C::const_reference, const char&>::value), "");
     43     static_assert((std::is_same<C::pointer, char*>::value), "");
     44     static_assert((std::is_same<C::const_pointer, const char*>::value), "");
     45     static_assert((std::is_same<C::size_type, std::size_t>::value), "");
     46     static_assert((std::is_same<C::difference_type, std::ptrdiff_t>::value), "");
     47 
     48     static_assert((std::is_signed<typename C::difference_type>::value), "");
     49     static_assert((std::is_unsigned<typename C::size_type>::value), "");
     50     static_assert((std::is_same<typename C::difference_type,
     51         typename std::iterator_traits<typename C::iterator>::difference_type>::value), "");
     52     static_assert((std::is_same<typename C::difference_type,
     53         typename std::iterator_traits<typename C::const_iterator>::difference_type>::value), "");
     54     }
     55 #if TEST_STD_VER >= 11
     56     {
     57     typedef std::forward_list<char, min_allocator<char>> C;
     58     static_assert((std::is_same<C::value_type, char>::value), "");
     59     static_assert((std::is_same<C::allocator_type, min_allocator<char> >::value), "");
     60     static_assert((std::is_same<C::reference, char&>::value), "");
     61     static_assert((std::is_same<C::const_reference, const char&>::value), "");
     62     static_assert((std::is_same<C::pointer, min_pointer<char>>::value), "");
     63     static_assert((std::is_same<C::const_pointer, min_pointer<const char>>::value), "");
     64 //  min_allocator doesn't have a size_type, so one gets synthesized
     65     static_assert((std::is_same<C::size_type, std::make_unsigned<C::difference_type>::type>::value), "");
     66     static_assert((std::is_same<C::difference_type, std::ptrdiff_t>::value), "");
     67 
     68     static_assert((std::is_signed<typename C::difference_type>::value), "");
     69     static_assert((std::is_unsigned<typename C::size_type>::value), "");
     70     static_assert((std::is_same<typename C::difference_type,
     71         typename std::iterator_traits<typename C::iterator>::difference_type>::value), "");
     72     static_assert((std::is_same<typename C::difference_type,
     73         typename std::iterator_traits<typename C::const_iterator>::difference_type>::value), "");
     74     }
     75 #endif
     76 }
     77