| 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 | typedef std::basic_string_view<typename Traits::char_type, Traits> S; |
| 44 | |
| 45 | static_assert((std::is_same<typename S::traits_type, Traits>::value), "" ); |
| 46 | static_assert((std::is_same<typename S::value_type, typename Traits::char_type>::value), "" ); |
| 47 | static_assert((std::is_same<typename S::size_type, std::size_t>::value), "" ); |
| 48 | static_assert((std::is_same<typename S::difference_type, std::ptrdiff_t>::value), "" ); |
| 49 | static_assert((std::is_same<typename S::reference, typename S::value_type&>::value), "" ); |
| 50 | static_assert((std::is_same<typename S::const_reference, const typename S::value_type&>::value), "" ); |
| 51 | static_assert((std::is_same<typename S::pointer, typename S::value_type*>::value), "" ); |
| 52 | static_assert((std::is_same<typename S::const_pointer, const typename S::value_type*>::value), "" ); |
| 53 | static_assert((std::is_same< typename std::iterator_traits<typename S::iterator>::iterator_category, |
| 54 | std::random_access_iterator_tag>::value), |
| 55 | "" ); |
| 56 | static_assert((std::is_same< typename std::iterator_traits<typename S::const_iterator>::iterator_category, |
| 57 | std::random_access_iterator_tag>::value), |
| 58 | "" ); |
| 59 | static_assert((std::is_same< typename S::reverse_iterator, std::reverse_iterator<typename S::iterator> >::value), "" ); |
| 60 | static_assert( |
| 61 | (std::is_same< typename S::const_reverse_iterator, std::reverse_iterator<typename S::const_iterator> >::value), |
| 62 | "" ); |
| 63 | static_assert(S::npos == -1, "" ); |
| 64 | static_assert((std::is_same<typename S::iterator, typename S::const_iterator>::value), "" ); |
| 65 | static_assert((std::is_same<typename S::reverse_iterator, typename S::const_reverse_iterator>::value), "" ); |
| 66 | } |
| 67 | |
| 68 | int main(int, char**) { |
| 69 | test<std::char_traits<char> >(); |
| 70 | #ifndef TEST_HAS_NO_WIDE_CHARACTERS |
| 71 | test<std::char_traits<wchar_t> >(); |
| 72 | #endif |
| 73 | #ifndef TEST_HAS_NO_CHAR8_T |
| 74 | test<std::char_traits<char8_t> >(); |
| 75 | #endif |
| 76 | static_assert((std::is_same<std::basic_string_view<char>::traits_type, std::char_traits<char> >::value), "" ); |
| 77 | |
| 78 | return 0; |
| 79 | } |
| 80 | |