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 // UNSUPPORTED: !stdlib=libc++ && (c++03 || c++11 || c++14)
10
11 // <string_view>
12
13 // Test nested types and default template args:
14
15 // template<class charT, class traits = char_traits<charT>>
16 // {
17 // public:
18 // // types:
19 // using traits_type = traits;
20 // using value_type = charT;
21 // using pointer = value_type*;
22 // using const_pointer = const value_type*;
23 // using reference = value_type&;
24 // using const_reference = const value_type&;
25 // using const_iterator = implementation-defined ; // see 24.4.2.2
26 // using iterator = const_iterator;
27 // using const_reverse_iterator = reverse_iterator<const_iterator>;
28 // using iterator = const_reverse_iterator;
29 // using size_type = size_t;
30 // using difference_type = ptrdiff_t;
31 // static constexpr size_type npos = size_type(-1);
32 //
33 // };
34
35 #include <string_view>
36 #include <iterator>
37 #include <type_traits>
38
39 #include "test_macros.h"
40
41 template <class Traits>
42 void
test()43 test()
44 {
45 typedef std::basic_string_view<typename Traits::char_type, Traits> S;
46
47 static_assert((std::is_same<typename S::traits_type, Traits>::value), "");
48 static_assert((std::is_same<typename S::value_type, typename Traits::char_type>::value), "");
49 static_assert((std::is_same<typename S::size_type, std::size_t>::value), "");
50 static_assert((std::is_same<typename S::difference_type, ptrdiff_t>::value), "");
51 static_assert((std::is_same<typename S::reference, typename S::value_type&>::value), "");
52 static_assert((std::is_same<typename S::const_reference, const typename S::value_type&>::value), "");
53 static_assert((std::is_same<typename S::pointer, typename S::value_type*>::value), "");
54 static_assert((std::is_same<typename S::const_pointer, const typename S::value_type*>::value), "");
55 static_assert((std::is_same<
56 typename std::iterator_traits<typename S::iterator>::iterator_category,
57 std::random_access_iterator_tag>::value), "");
58 static_assert((std::is_same<
59 typename std::iterator_traits<typename S::const_iterator>::iterator_category,
60 std::random_access_iterator_tag>::value), "");
61 static_assert((std::is_same<
62 typename S::reverse_iterator,
63 std::reverse_iterator<typename S::iterator> >::value), "");
64 static_assert((std::is_same<
65 typename S::const_reverse_iterator,
66 std::reverse_iterator<typename S::const_iterator> >::value), "");
67 static_assert(S::npos == -1, "");
68 static_assert((std::is_same<typename S::iterator, typename S::const_iterator>::value), "");
69 static_assert((std::is_same<typename S::reverse_iterator, typename S::const_reverse_iterator>::value), "");
70 }
71
main(int,char **)72 int main(int, char**)
73 {
74 test<std::char_traits<char> >();
75 test<std::char_traits<wchar_t> >();
76 #if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L
77 test<std::char_traits<char8_t> >();
78 #endif
79 static_assert((std::is_same<std::basic_string_view<char>::traits_type,
80 std::char_traits<char> >::value), "");
81
82 return 0;
83 }
84