| 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 | typedef std::basic_string<typename Traits::char_type, Traits, Allocator> 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::value_type, typename Allocator::value_type>::value), "" ); |
| 50 | static_assert((std::is_same<typename S::allocator_type, Allocator>::value), "" ); |
| 51 | static_assert((std::is_same<typename S::size_type, typename std::allocator_traits<Allocator>::size_type>::value), "" ); |
| 52 | static_assert( |
| 53 | (std::is_same<typename S::difference_type, typename std::allocator_traits<Allocator>::difference_type>::value), |
| 54 | "" ); |
| 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( |
| 59 | (std::is_same<typename S::const_pointer, typename std::allocator_traits<Allocator>::const_pointer>::value), "" ); |
| 60 | static_assert((std::is_same< typename std::iterator_traits<typename S::iterator>::iterator_category, |
| 61 | std::random_access_iterator_tag>::value), |
| 62 | "" ); |
| 63 | static_assert((std::is_same< typename std::iterator_traits<typename S::const_iterator>::iterator_category, |
| 64 | std::random_access_iterator_tag>::value), |
| 65 | "" ); |
| 66 | static_assert((std::is_same< typename S::reverse_iterator, std::reverse_iterator<typename S::iterator> >::value), "" ); |
| 67 | static_assert( |
| 68 | (std::is_same< typename S::const_reverse_iterator, std::reverse_iterator<typename S::const_iterator> >::value), |
| 69 | "" ); |
| 70 | static_assert(S::npos == -1, "" ); |
| 71 | } |
| 72 | |
| 73 | int main(int, char**) { |
| 74 | test<test_traits<char>, test_allocator<char> >(); |
| 75 | #ifndef TEST_HAS_NO_WIDE_CHARACTERS |
| 76 | test<std::char_traits<wchar_t>, std::allocator<wchar_t> >(); |
| 77 | #endif |
| 78 | static_assert((std::is_same<std::basic_string<char>::traits_type, std::char_traits<char> >::value), "" ); |
| 79 | static_assert((std::is_same<std::basic_string<char>::allocator_type, std::allocator<char> >::value), "" ); |
| 80 | #if TEST_STD_VER >= 11 |
| 81 | test<std::char_traits<char>, min_allocator<char> >(); |
| 82 | #endif |
| 83 | |
| 84 | return 0; |
| 85 | } |
| 86 | |