brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.4 KiB · 2c3e3b1 Raw
57 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// <string>10 11//       iterator end(); // constexpr since C++2012// const_iterator end() const; // constexpr since C++2013 14#include <string>15#include <cassert>16#include <cstddef>17 18#include "test_macros.h"19#include "min_allocator.h"20 21template <class S>22TEST_CONSTEXPR_CXX20 void test(S s) {23  const S& cs                   = s;24  typename S::iterator e        = s.end();25  typename S::const_iterator ce = cs.end();26  if (s.empty()) {27    assert(e == s.begin());28    assert(ce == cs.begin());29  }30  assert(static_cast<std::size_t>(e - s.begin()) == s.size());31  assert(static_cast<std::size_t>(ce - cs.begin()) == cs.size());32}33 34template <class S>35TEST_CONSTEXPR_CXX20 void test_string() {36  test(S());37  test(S("123"));38}39 40TEST_CONSTEXPR_CXX20 bool test() {41  test_string<std::string>();42#if TEST_STD_VER >= 1143  test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char> > >();44#endif45 46  return true;47}48 49int main(int, char**) {50  test();51#if TEST_STD_VER > 1752  static_assert(test());53#endif54 55  return 0;56}57