libcxx

libcxx mirror with random patches
git clone https://git.neptards.moe/neptards/libcxx.git
Log | Files | Refs

types.pass.cpp (3515B)


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