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