1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
12 // basic_string(const charT* s, const Allocator& a = Allocator());
20 #include "test_macros.h"
21 #include "test_allocator.h"
22 #include "min_allocator.h"
24 template <class charT>
28 typedef std::basic_string<charT, std::char_traits<charT>, test_allocator<charT> > S;
29 typedef typename S::traits_type T;
30 typedef typename S::allocator_type A;
31 std::size_t n = T::length(s);
33 LIBCPP_ASSERT(s2.__invariants());
34 assert(s2.size() == n);
35 assert(T::compare(s2.data(), s, n) == 0);
36 assert(s2.get_allocator() == A());
37 assert(s2.capacity() >= s2.size());
40 template <class charT, class A>
42 test(const charT* s, const A& a)
44 typedef std::basic_string<charT, std::char_traits<charT>, A> S;
45 typedef typename S::traits_type T;
46 std::size_t n = T::length(s);
48 LIBCPP_ASSERT(s2.__invariants());
49 assert(s2.size() == n);
50 assert(T::compare(s2.data(), s, n) == 0);
51 assert(s2.get_allocator() == a);
52 assert(s2.capacity() >= s2.size());
58 typedef test_allocator<char> A;
59 typedef std::basic_string<char, std::char_traits<char>, A> S;
68 test("1234567980", A(2));
70 test("123456798012345679801234567980123456798012345679801234567980");
71 test("123456798012345679801234567980123456798012345679801234567980", A(2));
73 #if TEST_STD_VER >= 11
75 typedef min_allocator<char> A;
76 typedef std::basic_string<char, std::char_traits<char>, A> S;
85 test("1234567980", A());
87 test("123456798012345679801234567980123456798012345679801234567980");
88 test("123456798012345679801234567980123456798012345679801234567980", A());