libcxx

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

iter_alloc_deduction.pass.cpp (3926B)


      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>
     11 // UNSUPPORTED: c++98, c++03, c++11, c++14
     12 // XFAIL: libcpp-no-deduction-guides
     13 
     14 // template<class InputIterator>
     15 //   basic_string(InputIterator begin, InputIterator end,
     16 //   const Allocator& a = Allocator());
     17 
     18 // template<class InputIterator,
     19 //      class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
     20 //  basic_string(InputIterator, InputIterator, Allocator = Allocator())
     21 //    -> basic_string<typename iterator_traits<InputIterator>::value_type,
     22 //                 char_traits<typename iterator_traits<InputIterator>::value_type>,
     23 //                 Allocator>;
     24 //
     25 //  The deduction guide shall not participate in overload resolution if InputIterator
     26 //  is a type that does not qualify as an input iterator, or if Allocator is a type
     27 //  that does not qualify as an allocator.
     28 
     29 
     30 #include <string>
     31 #include <iterator>
     32 #include <cassert>
     33 #include <cstddef>
     34 
     35 #include "test_macros.h"
     36 #include "test_allocator.h"
     37 #include "../input_iterator.h"
     38 #include "min_allocator.h"
     39 
     40 int main()
     41 {
     42     {
     43     const char* s = "12345678901234";
     44     std::basic_string s1(s, s+10);  // Can't use {} here
     45     using S = decltype(s1); // what type did we get?
     46     static_assert(std::is_same_v<S::value_type,                      char>,  "");
     47     static_assert(std::is_same_v<S::traits_type,    std::char_traits<char>>, "");
     48     static_assert(std::is_same_v<S::allocator_type,   std::allocator<char>>, "");
     49     assert(s1.size() == 10);
     50     assert(s1.compare(0, s1.size(), s, s1.size()) == 0);
     51     }
     52 
     53     {
     54     const char* s = "12345678901234";
     55     std::basic_string s1{s, s+10, std::allocator<char>{}};
     56     using S = decltype(s1); // what type did we get?
     57     static_assert(std::is_same_v<S::value_type,                      char>,  "");
     58     static_assert(std::is_same_v<S::traits_type,    std::char_traits<char>>, "");
     59     static_assert(std::is_same_v<S::allocator_type,   std::allocator<char>>, "");
     60     assert(s1.size() == 10);
     61     assert(s1.compare(0, s1.size(), s, s1.size()) == 0);
     62     }
     63     {
     64     const wchar_t* s = L"12345678901234";
     65     std::basic_string s1{s, s+10, test_allocator<wchar_t>{}};
     66     using S = decltype(s1); // what type did we get?
     67     static_assert(std::is_same_v<S::value_type,                      wchar_t>,  "");
     68     static_assert(std::is_same_v<S::traits_type,    std::char_traits<wchar_t>>, "");
     69     static_assert(std::is_same_v<S::allocator_type,   test_allocator<wchar_t>>, "");
     70     assert(s1.size() == 10);
     71     assert(s1.compare(0, s1.size(), s, s1.size()) == 0);
     72     }
     73     {
     74     const char16_t* s = u"12345678901234";
     75     std::basic_string s1{s, s+10, min_allocator<char16_t>{}};
     76     using S = decltype(s1); // what type did we get?
     77     static_assert(std::is_same_v<S::value_type,                      char16_t>,  "");
     78     static_assert(std::is_same_v<S::traits_type,    std::char_traits<char16_t>>, "");
     79     static_assert(std::is_same_v<S::allocator_type,    min_allocator<char16_t>>, "");
     80     assert(s1.size() == 10);
     81     assert(s1.compare(0, s1.size(), s, s1.size()) == 0);
     82     }
     83     {
     84     const char32_t* s = U"12345678901234";
     85     std::basic_string s1{s, s+10, explicit_allocator<char32_t>{}};
     86     using S = decltype(s1); // what type did we get?
     87     static_assert(std::is_same_v<S::value_type,                        char32_t>,  "");
     88     static_assert(std::is_same_v<S::traits_type,      std::char_traits<char32_t>>, "");
     89     static_assert(std::is_same_v<S::allocator_type, explicit_allocator<char32_t>>, "");
     90     assert(s1.size() == 10);
     91     assert(s1.compare(0, s1.size(), s, s1.size()) == 0);
     92     }
     93 }