55 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// const charT* c_str() const; // constexpr since C++2012 13#include <string>14#include <cassert>15 16#include "test_macros.h"17#include "min_allocator.h"18 19template <class S>20TEST_CONSTEXPR_CXX20 void test(const S& s) {21 typedef typename S::traits_type T;22 const typename S::value_type* str = s.c_str();23 if (s.size() > 0) {24 assert(T::compare(str, &s[0], s.size()) == 0);25 assert(T::eq(str[s.size()], typename S::value_type()));26 } else27 assert(T::eq(str[0], typename S::value_type()));28}29 30template <class S>31TEST_CONSTEXPR_CXX20 void test_string() {32 test(S(""));33 test(S("abcde"));34 test(S("abcdefghij"));35 test(S("abcdefghijklmnopqrst"));36}37 38TEST_CONSTEXPR_CXX20 bool test() {39 test_string<std::string>();40#if TEST_STD_VER >= 1141 test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char> > >();42#endif43 44 return true;45}46 47int main(int, char**) {48 test();49#if TEST_STD_VER > 1750 static_assert(test());51#endif52 53 return 0;54}55