blob: 517e5f6f21584d9f8251d0f92972732a9e0b7917 [file] [log] [blame]
Howard Hinnant3e519522010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
3// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// <string>
11
12// basic_string(const charT* s, const Allocator& a = Allocator());
13
14#include <string>
15#include <stdexcept>
16#include <algorithm>
17#include <cassert>
18
19#include "../test_allocator.h"
20
21template <class charT>
22void
23test(const charT* s)
24{
25 typedef std::basic_string<charT, std::char_traits<charT>, test_allocator<charT> > S;
26 typedef typename S::traits_type T;
27 typedef typename S::allocator_type A;
28 unsigned n = T::length(s);
29 S s2(s);
30 assert(s2.__invariants());
31 assert(s2.size() == n);
32 assert(T::compare(s2.data(), s, n) == 0);
33 assert(s2.get_allocator() == A());
34 assert(s2.capacity() >= s2.size());
35}
36
37template <class charT>
38void
39test(const charT* s, const test_allocator<charT>& a)
40{
41 typedef std::basic_string<charT, std::char_traits<charT>, test_allocator<charT> > S;
42 typedef typename S::traits_type T;
43 typedef typename S::allocator_type A;
44 unsigned n = T::length(s);
45 S s2(s, a);
46 assert(s2.__invariants());
47 assert(s2.size() == n);
48 assert(T::compare(s2.data(), s, n) == 0);
49 assert(s2.get_allocator() == a);
50 assert(s2.capacity() >= s2.size());
51}
52
53int main()
54{
55 typedef test_allocator<char> A;
56 typedef std::basic_string<char, std::char_traits<char>, A> S;
57
58 test("");
59 test("", A(2));
60
61 test("1");
62 test("1", A(2));
63
64 test("1234567980");
65 test("1234567980", A(2));
66
67 test("123456798012345679801234567980123456798012345679801234567980");
68 test("123456798012345679801234567980123456798012345679801234567980", A(2));
69}