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// <string> 11 12// Test nested types and default template args: 13 14// template<class charT, class traits = char_traits<charT>, 15// class Allocator = allocator<charT> > 16// { 17// public: 18// // types: 19// typedef traits traits_type; 20// typedef typename traits::char_type value_type; 21// typedef Allocator allocator_type; 22// typedef typename Allocator::size_type size_type; 23// typedef typename Allocator::difference_type difference_type; 24// typedef typename Allocator::reference reference; 25// typedef typename Allocator::const_reference const_reference; 26// typedef typename Allocator::pointer pointer; 27// typedef typename Allocator::const_pointer const_pointer; 28// typedef implementation-defined iterator; // See 23.1 29// typedef implementation-defined const_iterator; // See 23.1 30// typedef std::reverse_iterator<iterator> reverse_iterator; 31// typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 32// static const size_type npos = -1; 33// }; 34 35#include <string> 36#include <iterator> 37#include <type_traits> 38 39#include "test_traits.h" 40#include "test_allocator.h" 41#include "min_allocator.h" 42 43template <class Traits, class Allocator> 44void 45test() 46{ 47 typedef std::basic_string<typename Traits::char_type, Traits, Allocator> S; 48 49 static_assert((std::is_same<typename S::traits_type, Traits>::value), ""); 50 static_assert((std::is_same<typename S::value_type, typename Traits::char_type>::value), ""); 51 static_assert((std::is_same<typename S::value_type, typename Allocator::value_type>::value), ""); 52 static_assert((std::is_same<typename S::allocator_type, Allocator>::value), ""); 53 static_assert((std::is_same<typename S::size_type, typename std::allocator_traits<Allocator>::size_type>::value), ""); 54 static_assert((std::is_same<typename S::difference_type, typename std::allocator_traits<Allocator>::difference_type>::value), ""); 55 static_assert((std::is_same<typename S::reference, typename S::value_type&>::value), ""); 56 static_assert((std::is_same<typename S::const_reference, const typename S::value_type&>::value), ""); 57 static_assert((std::is_same<typename S::pointer, typename std::allocator_traits<Allocator>::pointer>::value), ""); 58 static_assert((std::is_same<typename S::const_pointer, typename std::allocator_traits<Allocator>::const_pointer>::value), ""); 59 static_assert((std::is_same< 60 typename std::iterator_traits<typename S::iterator>::iterator_category, 61 std::random_access_iterator_tag>::value), ""); 62 static_assert((std::is_same< 63 typename std::iterator_traits<typename S::const_iterator>::iterator_category, 64 std::random_access_iterator_tag>::value), ""); 65 static_assert((std::is_same< 66 typename S::reverse_iterator, 67 std::reverse_iterator<typename S::iterator> >::value), ""); 68 static_assert((std::is_same< 69 typename S::const_reverse_iterator, 70 std::reverse_iterator<typename S::const_iterator> >::value), ""); 71 static_assert(S::npos == -1, ""); 72} 73 74int main() 75{ 76 test<test_traits<char>, test_allocator<char> >(); 77 test<std::char_traits<wchar_t>, std::allocator<wchar_t> >(); 78 static_assert((std::is_same<std::basic_string<char>::traits_type, 79 std::char_traits<char> >::value), ""); 80 static_assert((std::is_same<std::basic_string<char>::allocator_type, 81 std::allocator<char> >::value), ""); 82#if __cplusplus >= 201103L 83 test<std::char_traits<char>, min_allocator<char> >(); 84#endif 85} 86