libcxx

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

from_ptr_len.pass.cpp (2081B)


      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 
     11 // <string_view>
     12 
     13 //  constexpr basic_string_view(const _CharT* _s, size_type _len)
     14 //      : __data (_s), __size(_len) {}
     15 
     16 
     17 #include <string_view>
     18 #include <string>
     19 #include <cassert>
     20 
     21 #include "test_macros.h"
     22 
     23 template<typename CharT>
     24 void test ( const CharT *s, size_t sz ) {
     25     {
     26     typedef std::basic_string_view<CharT> SV;
     27     LIBCPP_ASSERT_NOEXCEPT(SV(s, sz));
     28 
     29     SV sv1 ( s, sz );
     30     assert ( sv1.size() == sz );
     31     assert ( sv1.data() == s );
     32     }
     33 }
     34 
     35 int main () {
     36 
     37     test ( "QBCDE", 5 );
     38     test ( "QBCDE", 2 );
     39     test ( "", 0 );
     40 #if TEST_STD_VER > 11
     41     {
     42     constexpr const char *s = "QBCDE";
     43     constexpr std::basic_string_view<char> sv1 ( s, 2 );
     44     static_assert ( sv1.size() == 2, "" );
     45     static_assert ( sv1.data() == s, "" );
     46     }
     47 #endif
     48 
     49     test ( L"QBCDE", 5 );
     50     test ( L"QBCDE", 2 );
     51     test ( L"", 0 );
     52 #if TEST_STD_VER > 11
     53     {
     54     constexpr const wchar_t *s = L"QBCDE";
     55     constexpr std::basic_string_view<wchar_t> sv1 ( s, 2 );
     56     static_assert ( sv1.size() == 2, "" );
     57     static_assert ( sv1.data() == s, "" );
     58     }
     59 #endif
     60 
     61 #if TEST_STD_VER >= 11
     62     test ( u"QBCDE", 5 );
     63     test ( u"QBCDE", 2 );
     64     test ( u"", 0 );
     65 #if TEST_STD_VER > 11
     66     {
     67     constexpr const char16_t *s = u"QBCDE";
     68     constexpr std::basic_string_view<char16_t> sv1 ( s, 2 );
     69     static_assert ( sv1.size() == 2, "" );
     70     static_assert ( sv1.data() == s, "" );
     71     }
     72 #endif
     73 
     74     test ( U"QBCDE", 5 );
     75     test ( U"QBCDE", 2 );
     76     test ( U"", 0 );
     77 #if TEST_STD_VER > 11
     78     {
     79     constexpr const char32_t *s = U"QBCDE";
     80     constexpr std::basic_string_view<char32_t> sv1 ( s, 2 );
     81     static_assert ( sv1.size() == 2, "" );
     82     static_assert ( sv1.data() == s, "" );
     83     }
     84 #endif
     85 #endif
     86 }