Home | History | Annotate | Download | only in front.insert.iterator
      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 // <iterator>
     11 
     12 // front_insert_iterator
     13 
     14 // Test nested types and data member:
     15 
     16 // template <class Container>
     17 // class front_insert_iterator {
     18 // protected:
     19 //   Container* container;
     20 // public:
     21 //   typedef Container                   container_type;
     22 //   typedef void                        value_type;
     23 //   typedef void                        difference_type;
     24 //   typedef front_insert_iterator<Cont>& reference;
     25 //   typedef void                        pointer;
     26 //   typedef output_iterator_tag         iterator_category;
     27 // };
     28 
     29 #include <iterator>
     30 #include <type_traits>
     31 #include <vector>
     32 
     33 template <class C>
     34 struct find_container
     35     : private std::front_insert_iterator<C>
     36 {
     37     explicit find_container(C& c) : std::front_insert_iterator<C>(c) {}
     38     void test() {this->container = 0;}
     39 };
     40 
     41 template <class C>
     42 void
     43 test()
     44 {
     45     typedef std::front_insert_iterator<C> R;
     46     C c;
     47     find_container<C> q(c);
     48     q.test();
     49     static_assert((std::is_same<typename R::container_type, C>::value), "");
     50     static_assert((std::is_same<typename R::value_type, void>::value), "");
     51     static_assert((std::is_same<typename R::difference_type, void>::value), "");
     52     static_assert((std::is_same<typename R::reference, R&>::value), "");
     53     static_assert((std::is_same<typename R::pointer, void>::value), "");
     54     static_assert((std::is_same<typename R::iterator_category, std::output_iterator_tag>::value), "");
     55 }
     56 
     57 int main()
     58 {
     59     test<std::vector<int> >();
     60 }
     61