1*c5c29006SMarshall Clow //===----------------------------------------------------------------------===// 2*c5c29006SMarshall Clow // 3*c5c29006SMarshall Clow // The LLVM Compiler Infrastructure 4*c5c29006SMarshall Clow // 5*c5c29006SMarshall Clow // This file is dual licensed under the MIT and the University of Illinois Open 6*c5c29006SMarshall Clow // Source Licenses. See LICENSE.TXT for details. 7*c5c29006SMarshall Clow // 8*c5c29006SMarshall Clow //===----------------------------------------------------------------------===// 9*c5c29006SMarshall Clow 10*c5c29006SMarshall Clow // <array> 11*c5c29006SMarshall Clow 12*c5c29006SMarshall Clow // An string is a contiguous container 13*c5c29006SMarshall Clow 14*c5c29006SMarshall Clow #include <string> 15*c5c29006SMarshall Clow #include <cassert> 16*c5c29006SMarshall Clow 17*c5c29006SMarshall Clow #include "test_allocator.h" 18*c5c29006SMarshall Clow #include "min_allocator.h" 19*c5c29006SMarshall Clow 20*c5c29006SMarshall Clow 21*c5c29006SMarshall Clow template <class C> 22*c5c29006SMarshall Clow void test_contiguous ( const C &c ) 23*c5c29006SMarshall Clow { 24*c5c29006SMarshall Clow for ( size_t i = 0; i < c.size(); ++i ) 25*c5c29006SMarshall Clow assert ( *(c.begin() + i) == *(std::addressof(*c.begin()) + i)); 26*c5c29006SMarshall Clow } 27*c5c29006SMarshall Clow 28*c5c29006SMarshall Clow int main() 29*c5c29006SMarshall Clow { 30*c5c29006SMarshall Clow { 31*c5c29006SMarshall Clow typedef std::string S; 32*c5c29006SMarshall Clow test_contiguous(S()); 33*c5c29006SMarshall Clow test_contiguous(S("1")); 34*c5c29006SMarshall Clow test_contiguous(S("1234567890123456789012345678901234567890123456789012345678901234567890")); 35*c5c29006SMarshall Clow } 36*c5c29006SMarshall Clow 37*c5c29006SMarshall Clow { 38*c5c29006SMarshall Clow typedef test_allocator<char> A; 39*c5c29006SMarshall Clow typedef std::basic_string<char, std::char_traits<char>, A> S; 40*c5c29006SMarshall Clow test_contiguous(S(A(3))); 41*c5c29006SMarshall Clow test_contiguous(S("1", A(5))); 42*c5c29006SMarshall Clow test_contiguous(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7))); 43*c5c29006SMarshall Clow } 44*c5c29006SMarshall Clow #if __cplusplus >= 201103L 45*c5c29006SMarshall Clow { 46*c5c29006SMarshall Clow typedef min_allocator<char> A; 47*c5c29006SMarshall Clow typedef std::basic_string<char, std::char_traits<char>, A> S; 48*c5c29006SMarshall Clow test_contiguous(S(A{})); 49*c5c29006SMarshall Clow test_contiguous(S("1", A())); 50*c5c29006SMarshall Clow test_contiguous(S("1234567890123456789012345678901234567890123456789012345678901234567890", A())); 51*c5c29006SMarshall Clow } 52*c5c29006SMarshall Clow #endif 53*c5c29006SMarshall Clow } 54