types.pass.cpp revision f5256e16dfc425c1d466f6308d4026d529ce9e0b
1//===----------------------------------------------------------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. 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 back_insert_iterator<Cont>& reference; 25// typedef void pointer; 26// }; 27 28#include <iterator> 29#include <type_traits> 30#include <vector> 31 32template <class C> 33struct 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 40template <class C> 41void 42test() 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, R&>::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 56int main() 57{ 58 test<std::vector<int> >(); 59} 60