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