1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // <string>
10 
11 // Test nested types and default template args:
12 
13 // template<class charT, class traits = char_traits<charT>,
14 //   class Allocator = allocator<charT> >
15 // {
16 // public:
17 //     // types:
18 //     typedef traits traits_type;
19 //     typedef typename traits::char_type value_type;
20 //     typedef Allocator allocator_type;
21 //     typedef typename Allocator::size_type size_type;
22 //     typedef typename Allocator::difference_type difference_type;
23 //     typedef typename Allocator::reference reference;
24 //     typedef typename Allocator::const_reference const_reference;
25 //     typedef typename Allocator::pointer pointer;
26 //     typedef typename Allocator::const_pointer const_pointer;
27 //     typedef implementation-defined iterator; // See 23.1
28 //     typedef implementation-defined const_iterator; // See 23.1
29 //     typedef std::reverse_iterator<iterator> reverse_iterator;
30 //     typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
31 //     static const size_type npos = -1;
32 // };
33 
34 #include <string>
35 #include <iterator>
36 #include <type_traits>
37 
38 #include "test_macros.h"
39 #include "test_traits.h"
40 #include "test_allocator.h"
41 #include "min_allocator.h"
42 
43 template <class Traits, class Allocator>
44 void
test()45 test()
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 
main(int,char **)74 int main(int, char**)
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 TEST_STD_VER >= 11
83     test<std::char_traits<char>, min_allocator<char> >();
84 #endif
85 
86   return 0;
87 }
88