brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.8 KiB · 7890890 Raw
66 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// <array>10 11// A string is a contiguous container12 13#include <string>14#include <cassert>15 16#include "test_macros.h"17#include "test_allocator.h"18#include "min_allocator.h"19 20template <class C>21TEST_CONSTEXPR_CXX20 void test_contiguous(const C& c) {22  for (std::size_t i = 0; i < c.size(); ++i)23    assert(*(c.begin() + static_cast<typename C::difference_type>(i)) == *(std::addressof(*c.begin()) + i));24}25 26template <class Alloc>27TEST_CONSTEXPR_CXX20 void test_string(const Alloc& a) {28  typedef std::basic_string<char, std::char_traits<char>, Alloc> S;29 30  {31    test_contiguous(S());32    test_contiguous(S("1"));33    test_contiguous(S("1234567890123456789012345678901234567890123456789012345678901234567890"));34  }35  {36    test_contiguous(S(Alloc()));37    test_contiguous(S("1", Alloc()));38    test_contiguous(S("1234567890123456789012345678901234567890123456789012345678901234567890", Alloc()));39  }40  {41    test_contiguous(S(Alloc(a)));42    test_contiguous(S("1", Alloc(a)));43    test_contiguous(S("1234567890123456789012345678901234567890123456789012345678901234567890", Alloc(a)));44  }45}46 47TEST_CONSTEXPR_CXX20 bool test() {48  test_string(std::allocator<char>());49  test_string(test_allocator<char>());50  test_string(test_allocator<char>(3));51#if TEST_STD_VER >= 1152  test_string(min_allocator<char>());53#endif54 55  return true;56}57 58int main(int, char**) {59  test();60#if TEST_STD_VER > 1761  static_assert(test());62#endif63 64  return 0;65}66