1c5c29006SMarshall Clow //===----------------------------------------------------------------------===// 2c5c29006SMarshall Clow // 357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6c5c29006SMarshall Clow // 7c5c29006SMarshall Clow //===----------------------------------------------------------------------===// 8c5c29006SMarshall Clow 9*425620ccSNikolas Klauser // XFAIL: LIBCXX-AIX-FIXME 10*425620ccSNikolas Klauser 11c5c29006SMarshall Clow // <array> 12c5c29006SMarshall Clow 13c5c29006SMarshall Clow // An string is a contiguous container 14c5c29006SMarshall Clow 15c5c29006SMarshall Clow #include <string> 16c5c29006SMarshall Clow #include <cassert> 17c5c29006SMarshall Clow 187fc6a556SMarshall Clow #include "test_macros.h" 19c5c29006SMarshall Clow #include "test_allocator.h" 20c5c29006SMarshall Clow #include "min_allocator.h" 21c5c29006SMarshall Clow 22c5c29006SMarshall Clow 23c5c29006SMarshall Clow template <class C> 24*425620ccSNikolas Klauser TEST_CONSTEXPR_CXX20 void test_contiguous ( const C &c ) 25c5c29006SMarshall Clow { 26c5c29006SMarshall Clow for ( size_t i = 0; i < c.size(); ++i ) 27286adee5SStephan T. Lavavej assert ( *(c.begin() + static_cast<typename C::difference_type>(i)) == *(std::addressof(*c.begin()) + i)); 28c5c29006SMarshall Clow } 29c5c29006SMarshall Clow 30*425620ccSNikolas Klauser TEST_CONSTEXPR_CXX20 bool test() { 31c5c29006SMarshall Clow { 32c5c29006SMarshall Clow typedef std::string S; 33c5c29006SMarshall Clow test_contiguous(S()); 34c5c29006SMarshall Clow test_contiguous(S("1")); 35c5c29006SMarshall Clow test_contiguous(S("1234567890123456789012345678901234567890123456789012345678901234567890")); 36c5c29006SMarshall Clow } 37c5c29006SMarshall Clow 38c5c29006SMarshall Clow { 39c5c29006SMarshall Clow typedef test_allocator<char> A; 40c5c29006SMarshall Clow typedef std::basic_string<char, std::char_traits<char>, A> S; 41c5c29006SMarshall Clow test_contiguous(S(A(3))); 42c5c29006SMarshall Clow test_contiguous(S("1", A(5))); 43c5c29006SMarshall Clow test_contiguous(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7))); 44c5c29006SMarshall Clow } 45f2f2a639SEric Fiselier #if TEST_STD_VER >= 11 46c5c29006SMarshall Clow { 47c5c29006SMarshall Clow typedef min_allocator<char> A; 48c5c29006SMarshall Clow typedef std::basic_string<char, std::char_traits<char>, A> S; 49c5c29006SMarshall Clow test_contiguous(S(A{})); 50c5c29006SMarshall Clow test_contiguous(S("1", A())); 51c5c29006SMarshall Clow test_contiguous(S("1234567890123456789012345678901234567890123456789012345678901234567890", A())); 52c5c29006SMarshall Clow } 53c5c29006SMarshall Clow #endif 542df59c50SJF Bastien 55c515b652SNikolas Klauser return true; 56c515b652SNikolas Klauser } 57c515b652SNikolas Klauser 58c515b652SNikolas Klauser int main(int, char**) 59c515b652SNikolas Klauser { 60c515b652SNikolas Klauser test(); 61c515b652SNikolas Klauser #if TEST_STD_VER > 17 62*425620ccSNikolas Klauser static_assert(test()); 63c515b652SNikolas Klauser #endif 64c515b652SNikolas Klauser 652df59c50SJF Bastien return 0; 66c5c29006SMarshall Clow } 67