Initial commit

This commit is contained in:
Yervant7
2024-01-16 19:28:29 -03:00
commit 8c0524dc0f
9054 changed files with 1081727 additions and 0 deletions
@@ -0,0 +1,196 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <string>
// template<class _Tp>
// basic_string(const _Tp& __t, size_type __pos, size_type __n,
// const allocator_type& __a = allocator_type()); // constexpr since C++20
//
// Mostly we're testing string_view here
#include <string>
#include <string_view>
#include <stdexcept>
#include <algorithm>
#include <cassert>
#include "test_macros.h"
#include "test_allocator.h"
#include "min_allocator.h"
template <class S, class SV>
TEST_CONSTEXPR_CXX20 void
test(SV sv, std::size_t pos, std::size_t n)
{
typedef typename S::traits_type T;
typedef typename S::allocator_type A;
typedef typename S::size_type Size;
if (pos <= sv.size())
{
S s2(sv, static_cast<Size>(pos), static_cast<Size>(n));
LIBCPP_ASSERT(s2.__invariants());
assert(pos <= sv.size());
std::size_t rlen = std::min(sv.size() - pos, n);
assert(s2.size() == rlen);
assert(T::compare(s2.data(), sv.data() + pos, rlen) == 0);
assert(s2.get_allocator() == A());
assert(s2.capacity() >= s2.size());
}
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED)
{
try
{
S s2(sv, static_cast<Size>(pos), static_cast<Size>(n));
assert(false);
}
catch (std::out_of_range&)
{
assert(pos > sv.size());
}
}
#endif
}
template <class S, class SV>
TEST_CONSTEXPR_CXX20 void
test(SV sv, std::size_t pos, std::size_t n, const typename S::allocator_type& a)
{
typedef typename S::traits_type T;
typedef typename S::size_type Size;
if (pos <= sv.size())
{
S s2(sv, static_cast<Size>(pos), static_cast<Size>(n), a);
LIBCPP_ASSERT(s2.__invariants());
assert(pos <= sv.size());
std::size_t rlen = std::min(sv.size() - pos, n);
assert(s2.size() == rlen);
assert(T::compare(s2.data(), sv.data() + pos, rlen) == 0);
assert(s2.get_allocator() == a);
assert(s2.capacity() >= s2.size());
}
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED)
{
try
{
S s2(sv, static_cast<Size>(pos), static_cast<Size>(n), a);
assert(false);
}
catch (std::out_of_range&)
{
assert(pos > sv.size());
}
}
#endif
}
TEST_CONSTEXPR_CXX20 bool test() {
{
typedef test_allocator<char> A;
typedef std::basic_string_view<char, std::char_traits<char> > SV;
typedef std::basic_string <char, std::char_traits<char>, A> S;
test<S,SV>(SV(), 0, 0);
test<S,SV>(SV(), 0, 1);
test<S,SV>(SV(), 1, 0);
test<S,SV>(SV(), 1, 1);
test<S,SV>(SV(), 1, 2);
test<S,SV>(SV("1"), 0, 0);
test<S,SV>(SV("1"), 0, 1);
test<S,SV>(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 0);
test<S,SV>(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 1);
test<S,SV>(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 10);
test<S,SV>(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 100);
test<S,SV>(SV(), 0, 0, A(4));
test<S,SV>(SV(), 0, 1, A(4));
test<S,SV>(SV(), 1, 0, A(4));
test<S,SV>(SV(), 1, 1, A(4));
test<S,SV>(SV(), 1, 2, A(4));
test<S,SV>(SV("1"), 0, 0, A(6));
test<S,SV>(SV("1"), 0, 1, A(6));
test<S,SV>(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 0, A(8));
test<S,SV>(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 1, A(8));
test<S,SV>(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 10, A(8));
test<S,SV>(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 100, A(8));
}
#if TEST_STD_VER >= 11
{
typedef min_allocator<char> A;
typedef std::basic_string_view<char, std::char_traits<char> > SV;
typedef std::basic_string <char, std::char_traits<char>, A> S;
test<S,SV>(SV(), 0, 0);
test<S,SV>(SV(), 0, 1);
test<S,SV>(SV(), 1, 0);
test<S,SV>(SV(), 1, 1);
test<S,SV>(SV(), 1, 2);
test<S,SV>(SV("1"), 0, 0);
test<S,SV>(SV("1"), 0, 1);
test<S,SV>(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 0);
test<S,SV>(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 1);
test<S,SV>(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 10);
test<S,SV>(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 100);
test<S,SV>(SV(), 0, 0, A());
test<S,SV>(SV(), 0, 1, A());
test<S,SV>(SV(), 1, 0, A());
test<S,SV>(SV(), 1, 1, A());
test<S,SV>(SV(), 1, 2, A());
test<S,SV>(SV("1"), 0, 0, A());
test<S,SV>(SV("1"), 0, 1, A());
test<S,SV>(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 0, A());
test<S,SV>(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 1, A());
test<S,SV>(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 10, A());
test<S,SV>(SV("1234567890123456789012345678901234567890123456789012345678901234567890"), 50, 100, A());
}
#endif
{
typedef std::string S;
typedef std::string_view SV;
S s = "ABCD";
SV sv = "EFGH";
char arr[] = "IJKL";
S s1("CDEF", 4); // calls ctor(const char *, len)
assert(s1 == "CDEF");
S s2("QRST", 0, 3); // calls ctor(string("QRST", pos, len)
assert(s2 == "QRS");
S s3(sv, 0, std::string::npos); // calls ctor(T, pos, npos)
assert(s3 == sv);
S s4(sv, 0, 3); // calls ctor(T, pos, len)
assert(s4 == "EFG");
S s5(arr, 0, 2); // calls ctor(const char *, len)
assert(s5 == "IJ");
S s6(arr, 0); // calls ctor(const char *, len)
assert(s6 == "");
S s7(s.data(), 2); // calls ctor(const char *, len)
assert(s7 == "AB");
}
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
static_assert(test());
#endif
return 0;
}
@@ -0,0 +1,106 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <string>
// explicit basic_string(const Allocator& a = Allocator()); // constexpr since C++20
#include <string>
#include <cassert>
#include "test_macros.h"
#include "test_allocator.h"
#include "min_allocator.h"
template <class S>
TEST_CONSTEXPR_CXX20 void
test()
{
{
#if TEST_STD_VER > 14
static_assert((noexcept(S{})), "" );
#elif TEST_STD_VER >= 11
static_assert((noexcept(S()) == noexcept(typename S::allocator_type())), "" );
#endif
S s;
LIBCPP_ASSERT(s.__invariants());
assert(s.data());
assert(s.size() == 0);
assert(s.capacity() >= s.size());
assert(s.get_allocator() == typename S::allocator_type());
}
{
#if TEST_STD_VER > 14
static_assert((noexcept(S{typename S::allocator_type{}})), "" );
#elif TEST_STD_VER >= 11
static_assert((noexcept(S(typename S::allocator_type())) == std::is_nothrow_copy_constructible<typename S::allocator_type>::value), "" );
#endif
S s(typename S::allocator_type(5));
LIBCPP_ASSERT(s.__invariants());
assert(s.data());
assert(s.size() == 0);
assert(s.capacity() >= s.size());
assert(s.get_allocator() == typename S::allocator_type(5));
}
}
#if TEST_STD_VER >= 11
template <class S>
TEST_CONSTEXPR_CXX20 void
test2()
{
{
#if TEST_STD_VER > 14
static_assert((noexcept(S{})), "" );
#elif TEST_STD_VER >= 11
static_assert((noexcept(S()) == noexcept(typename S::allocator_type())), "" );
#endif
S s;
LIBCPP_ASSERT(s.__invariants());
assert(s.data());
assert(s.size() == 0);
assert(s.capacity() >= s.size());
assert(s.get_allocator() == typename S::allocator_type());
}
{
#if TEST_STD_VER > 14
static_assert((noexcept(S{typename S::allocator_type{}})), "" );
#elif TEST_STD_VER >= 11
static_assert((noexcept(S(typename S::allocator_type())) == std::is_nothrow_copy_constructible<typename S::allocator_type>::value), "" );
#endif
S s(typename S::allocator_type{});
LIBCPP_ASSERT(s.__invariants());
assert(s.data());
assert(s.size() == 0);
assert(s.capacity() >= s.size());
assert(s.get_allocator() == typename S::allocator_type());
}
}
#endif
TEST_CONSTEXPR_CXX20 bool test() {
test<std::basic_string<char, std::char_traits<char>, test_allocator<char> > >();
#if TEST_STD_VER >= 11
test2<std::basic_string<char, std::char_traits<char>, min_allocator<char> > >();
test2<std::basic_string<char, std::char_traits<char>, explicit_allocator<char> > >();
#endif
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
static_assert(test());
#endif
return 0;
}
@@ -0,0 +1,46 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// <string>
// basic_string<charT,traits,Allocator>&
// operator=(basic_string<charT,traits,Allocator>&& str); // constexpr since C++20
#include <string>
#include <cassert>
#include "test_macros.h"
TEST_CONSTEXPR_CXX20 bool test() {
// Test that assignment from {} and {ptr, len} are allowed and are not
// ambiguous.
{
std::string s = "hello world";
s = {};
assert(s.empty());
}
{
std::string s = "hello world";
s = {"abc", 2};
assert(s == "ab");
}
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
static_assert(test());
#endif
return 0;
}
@@ -0,0 +1,60 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <string>
// basic_string<charT,traits,Allocator>& operator=(charT c); // constexpr since C++20
#include <string>
#include <cassert>
#include "test_macros.h"
#include "min_allocator.h"
template <class S>
TEST_CONSTEXPR_CXX20 void
test(S s1, typename S::value_type s2)
{
typedef typename S::traits_type T;
s1 = s2;
LIBCPP_ASSERT(s1.__invariants());
assert(s1.size() == 1);
assert(T::eq(s1[0], s2));
assert(s1.capacity() >= s1.size());
}
TEST_CONSTEXPR_CXX20 bool test() {
{
typedef std::string S;
test(S(), 'a');
test(S("1"), 'a');
test(S("123456789"), 'a');
test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), 'a');
}
#if TEST_STD_VER >= 11
{
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
test(S(), 'a');
test(S("1"), 'a');
test(S("123456789"), 'a');
test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), 'a');
}
#endif
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
static_assert(test());
#endif
return 0;
}
@@ -0,0 +1,60 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <string>
// basic_string(const basic_string<charT,traits,Allocator>& str); // constexpr since C++20
#include <string>
#include <cassert>
#include "test_macros.h"
#include "test_allocator.h"
#include "min_allocator.h"
template <class S>
TEST_CONSTEXPR_CXX20 void
test(S s1)
{
S s2 = s1;
LIBCPP_ASSERT(s2.__invariants());
assert(s2 == s1);
assert(s2.capacity() >= s2.size());
assert(s2.get_allocator() == s1.get_allocator());
}
TEST_CONSTEXPR_CXX20 bool test() {
{
typedef test_allocator<char> A;
typedef std::basic_string<char, std::char_traits<char>, A> S;
test(S(A(3)));
test(S("1", A(5)));
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)));
}
#if TEST_STD_VER >= 11
{
typedef min_allocator<char> A;
typedef std::basic_string<char, std::char_traits<char>, A> S;
test(S(A{}));
test(S("1", A()));
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()));
}
#endif
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
static_assert(test());
#endif
return 0;
}
@@ -0,0 +1,142 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <string>
// basic_string(const basic_string& str, const Allocator& alloc); // constexpr since C++20
#include <string>
#include <cassert>
#include "test_macros.h"
#include "test_allocator.h"
#include "min_allocator.h"
#ifndef TEST_HAS_NO_EXCEPTIONS
struct alloc_imp {
bool active;
TEST_CONSTEXPR alloc_imp() : active(true) {}
template <class T>
T* allocate(std::size_t n)
{
if (active)
return static_cast<T*>(std::malloc(n * sizeof(T)));
else
throw std::bad_alloc();
}
template <class T>
void deallocate(T* p, std::size_t) { std::free(p); }
void activate () { active = true; }
void deactivate() { active = false; }
};
template <class T>
struct poca_alloc {
typedef T value_type;
typedef std::true_type propagate_on_container_copy_assignment;
alloc_imp *imp;
TEST_CONSTEXPR poca_alloc(alloc_imp *imp_) : imp (imp_) {}
template <class U>
TEST_CONSTEXPR poca_alloc(const poca_alloc<U>& other) : imp(other.imp) {}
T* allocate (std::size_t n) { return imp->allocate<T>(n);}
void deallocate(T* p, std::size_t n) { imp->deallocate(p, n); }
};
template <typename T, typename U>
bool operator==(const poca_alloc<T>& lhs, const poca_alloc<U>& rhs)
{
return lhs.imp == rhs.imp;
}
template <typename T, typename U>
bool operator!=(const poca_alloc<T>& lhs, const poca_alloc<U>& rhs)
{
return lhs.imp != rhs.imp;
}
template <class S>
TEST_CONSTEXPR_CXX20 void test_assign(S &s1, const S& s2)
{
try { s1 = s2; }
catch ( std::bad_alloc &) { return; }
assert(false);
}
#endif
template <class S>
TEST_CONSTEXPR_CXX20 void
test(S s1, const typename S::allocator_type& a)
{
S s2(s1, a);
LIBCPP_ASSERT(s2.__invariants());
assert(s2 == s1);
assert(s2.capacity() >= s2.size());
assert(s2.get_allocator() == a);
}
TEST_CONSTEXPR_CXX20 bool test() {
{
typedef test_allocator<char> A;
typedef std::basic_string<char, std::char_traits<char>, A> S;
test(S(), A(3));
test(S("1"), A(5));
test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), A(7));
}
#if TEST_STD_VER >= 11
{
typedef min_allocator<char> A;
typedef std::basic_string<char, std::char_traits<char>, A> S;
test(S(), A());
test(S("1"), A());
test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), A());
}
#ifndef TEST_HAS_NO_EXCEPTIONS
if (!TEST_IS_CONSTANT_EVALUATED) {
typedef poca_alloc<char> A;
typedef std::basic_string<char, std::char_traits<char>, A> S;
const char * p1 = "This is my first string";
const char * p2 = "This is my second string";
alloc_imp imp1;
alloc_imp imp2;
S s1(p1, A(&imp1));
S s2(p2, A(&imp2));
assert(s1 == p1);
assert(s2 == p2);
imp2.deactivate();
test_assign(s1, s2);
assert(s1 == p1);
assert(s2 == p2);
}
#endif
#endif
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
static_assert(test());
#endif
return 0;
}
@@ -0,0 +1,90 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <string>
// basic_string<charT,traits,Allocator>&
// operator=(const basic_string<charT,traits,Allocator>& str); // constexpr since C++20
#include <string>
#include <cassert>
#include "test_macros.h"
#include "min_allocator.h"
template <class S>
TEST_CONSTEXPR_CXX20 void
test(S s1, const S& s2)
{
s1 = s2;
LIBCPP_ASSERT(s1.__invariants());
assert(s1 == s2);
assert(s1.capacity() >= s1.size());
}
TEST_CONSTEXPR_CXX20 bool test() {
{
typedef std::string S;
test(S(), S());
test(S("1"), S());
test(S(), S("1"));
test(S("1"), S("2"));
test(S("1"), S("2"));
test(S(),
S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
test(S("123456789"),
S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
test(S("1234567890123456789012345678901234567890123456789012345678901234567890"),
S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
test(S("1234567890123456789012345678901234567890123456789012345678901234567890"
"1234567890123456789012345678901234567890123456789012345678901234567890"),
S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
}
#if TEST_STD_VER >= 11
{
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
test(S(), S());
test(S("1"), S());
test(S(), S("1"));
test(S("1"), S("2"));
test(S("1"), S("2"));
test(S(),
S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
test(S("123456789"),
S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
test(S("1234567890123456789012345678901234567890123456789012345678901234567890"),
S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
test(S("1234567890123456789012345678901234567890123456789012345678901234567890"
"1234567890123456789012345678901234567890123456789012345678901234567890"),
S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
}
#endif
#if TEST_STD_VER > 3
{ // LWG 2946
std::string s;
s = {"abc", 1};
assert(s.size() == 1);
assert(s == "a");
}
#endif
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
static_assert(test());
#endif
return 0;
}
@@ -0,0 +1,43 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <string>
// basic_string() noexcept(is_nothrow_default_constructible<allocator_type>::value); // constexpr since C++20
#include <cassert>
#include <string>
#include "test_macros.h"
#include "test_allocator.h"
#if TEST_STD_VER >= 11
// Test the noexcept specification, which is a conforming extension
LIBCPP_STATIC_ASSERT(std::is_nothrow_default_constructible<std::string>::value, "");
LIBCPP_STATIC_ASSERT(std::is_nothrow_default_constructible<
std::basic_string<char, std::char_traits<char>, test_allocator<char>>>::value, "");
LIBCPP_STATIC_ASSERT(!std::is_nothrow_default_constructible<
std::basic_string<char, std::char_traits<char>, limited_allocator<char, 10>>>::value, "");
#endif
TEST_CONSTEXPR_CXX20 bool test() {
std::string str;
assert(str.empty());
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
static_assert(test());
#endif
return 0;
}
@@ -0,0 +1,63 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// <string>
// ~basic_string() // implied noexcept; // constexpr since C++20
#include <string>
#include <cassert>
#include "test_macros.h"
#include "test_allocator.h"
template <class T>
struct throwing_alloc
{
typedef T value_type;
throwing_alloc(const throwing_alloc&);
T *allocate(size_t);
~throwing_alloc() noexcept(false);
};
// Test that it's possible to take the address of basic_string's destructors
// by creating globals which will register their destructors with cxa_atexit.
std::string s;
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
std::wstring ws;
#endif
static_assert(std::is_nothrow_destructible<std::string>::value, "");
static_assert(std::is_nothrow_destructible<
std::basic_string<char, std::char_traits<char>, test_allocator<char>>>::value, "");
LIBCPP_STATIC_ASSERT(!std::is_nothrow_destructible<
std::basic_string<char, std::char_traits<char>, throwing_alloc<char>>>::value, "");
TEST_CONSTEXPR_CXX20 bool test() {
test_allocator_statistics alloc_stats;
{
std::basic_string<char, std::char_traits<char>, test_allocator<char>> str2((test_allocator<char>(&alloc_stats)));
str2 = "long long string so no SSO";
assert(alloc_stats.alloc_count == 1);
}
assert(alloc_stats.alloc_count == 0);
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
static_assert(test());
#endif
return 0;
}
@@ -0,0 +1,379 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14
// <string>
// Test that the constructors offered by std::basic_string are formulated
// so they're compatible with implicit deduction guides.
#include <string>
#include <string_view>
#include <cassert>
#include "test_macros.h"
#include "test_allocator.h"
#include "test_iterators.h"
#include "constexpr_char_traits.h"
template <class T, class Alloc = std::allocator<T>>
using BStr = std::basic_string<T, std::char_traits<T>, Alloc>;
// Overloads
// using A = Allocator;
// using BS = basic_string
// using BSV = basic_string_view
// ---------------
// (1) basic_string() - NOT TESTED
// (2) basic_string(A const&) - BROKEN
// (3) basic_string(size_type, CharT, const A& = A())
// (4) basic_string(BS const&, size_type, A const& = A())
// (5) basic_string(BS const&, size_type, size_type, A const& = A())
// (6) basic_string(const CharT*, size_type, A const& = A())
// (7) basic_string(const CharT*, A const& = A())
// (8) basic_string(InputIt, InputIt, A const& = A()) - BROKEN
// (9) basic_string(BS const&)
// (10) basic_string(BS const&, A const&)
// (11) basic_string(BS&&)
// (12) basic_string(BS&&, A const&)
// (13) basic_string(initializer_list<CharT>, A const& = A())
// (14) basic_string(BSV, A const& = A())
// (15) basic_string(const T&, size_type, size_type, A const& = A())
TEST_CONSTEXPR_CXX20 bool test() {
using TestSizeT = test_allocator<char>::size_type;
{ // Testing (1)
// Nothing to do. Cannot deduce without any arguments.
}
{ // Testing (2)
// This overload isn't compatible with implicit deduction guides as
// specified in the standard.
// const test_allocator<char> alloc{};
// std::basic_string s(alloc);
}
{ // Testing (3) w/o allocator
std::basic_string s(6ull, 'a');
ASSERT_SAME_TYPE(decltype(s), std::string);
assert(s == "aaaaaa");
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
std::basic_string w(2ull, L'b');
ASSERT_SAME_TYPE(decltype(w), std::wstring);
assert(w == L"bb");
#endif
}
{ // Testing (3) w/ allocator
std::basic_string s(6ull, 'a', test_allocator<char>{});
ASSERT_SAME_TYPE(decltype(s), BStr<char,test_allocator<char>>);
assert(s == "aaaaaa");
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
std::basic_string w(2ull, L'b', test_allocator<wchar_t>{});
ASSERT_SAME_TYPE(decltype(w), BStr<wchar_t, test_allocator<wchar_t>>);
assert(w == L"bb");
#endif
}
{ // Testing (4) w/o allocator
const std::string sin("abc");
std::basic_string s(sin, (size_t)1);
ASSERT_SAME_TYPE(decltype(s), std::string);
assert(s == "bc");
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
using WStr = std::basic_string<wchar_t,
constexpr_char_traits<wchar_t>,
test_allocator<wchar_t>>;
const WStr win(L"abcdef");
std::basic_string w(win, (TestSizeT)3);
ASSERT_SAME_TYPE(decltype(w), WStr);
assert(w == L"def");
#endif
}
{ // Testing (4) w/ allocator
const std::string sin("abc");
std::basic_string s(sin, (size_t)1, std::allocator<char>{});
ASSERT_SAME_TYPE(decltype(s), std::string);
assert(s == "bc");
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
using WStr = std::basic_string<wchar_t,
constexpr_char_traits<wchar_t>,
test_allocator<wchar_t>>;
const WStr win(L"abcdef");
std::basic_string w(win, (TestSizeT)3, test_allocator<wchar_t>{});
ASSERT_SAME_TYPE(decltype(w), WStr);
assert(w == L"def");
#endif
}
{ // Testing (5) w/o allocator
const std::string sin("abc");
std::basic_string s(sin, (size_t)1, (size_t)3);
ASSERT_SAME_TYPE(decltype(s), std::string);
assert(s == "bc");
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
using WStr = std::basic_string<wchar_t,
constexpr_char_traits<wchar_t>,
test_allocator<wchar_t>>;
const WStr win(L"abcdef");
std::basic_string w(win, (TestSizeT)2, (TestSizeT)3);
ASSERT_SAME_TYPE(decltype(w), WStr);
assert(w == L"cde");
#endif
}
{ // Testing (5) w/ allocator
const std::string sin("abc");
std::basic_string s(sin, (size_t)1, (size_t)3, std::allocator<char>{});
ASSERT_SAME_TYPE(decltype(s), std::string);
assert(s == "bc");
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
using WStr = std::basic_string<wchar_t,
constexpr_char_traits<wchar_t>,
test_allocator<wchar_t>>;
const WStr win(L"abcdef");
std::basic_string w(win, (TestSizeT)2, (TestSizeT)3, test_allocator<wchar_t>{});
ASSERT_SAME_TYPE(decltype(w), WStr);
assert(w == L"cde");
#endif
}
{ // Testing (6) w/o allocator
std::basic_string s("abc", (size_t)2);
ASSERT_SAME_TYPE(decltype(s), std::string);
assert(s == "ab");
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
std::basic_string w(L"abcdef", (size_t)3);
ASSERT_SAME_TYPE(decltype(w), std::wstring);
assert(w == L"abc");
#endif
}
{ // Testing (6) w/ allocator
std::basic_string s("abc", (size_t)2, std::allocator<char>{});
ASSERT_SAME_TYPE(decltype(s), std::string);
assert(s == "ab");
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
using WStr = std::basic_string<wchar_t,
std::char_traits<wchar_t>,
test_allocator<wchar_t>>;
std::basic_string w(L"abcdef", (TestSizeT)3, test_allocator<wchar_t>{});
ASSERT_SAME_TYPE(decltype(w), WStr);
assert(w == L"abc");
#endif
}
{ // Testing (7) w/o allocator
std::basic_string s("abc");
ASSERT_SAME_TYPE(decltype(s), std::string);
assert(s == "abc");
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
std::basic_string w(L"abcdef");
ASSERT_SAME_TYPE(decltype(w), std::wstring);
assert(w == L"abcdef");
#endif
}
{ // Testing (7) w/ allocator
std::basic_string s("abc", std::allocator<char>{});
ASSERT_SAME_TYPE(decltype(s), std::string);
assert(s == "abc");
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
using WStr = std::basic_string<wchar_t,
std::char_traits<wchar_t>,
test_allocator<wchar_t>>;
std::basic_string w(L"abcdef", test_allocator<wchar_t>{});
ASSERT_SAME_TYPE(decltype(w), WStr);
assert(w == L"abcdef");
#endif
}
{ // (8) w/o allocator
using It = cpp17_input_iterator<const char*>;
const char* input = "abcdef";
std::basic_string s(It(input), It(input + 3), std::allocator<char>{});
ASSERT_SAME_TYPE(decltype(s), std::string);
assert(s == "abc");
}
{ // (8) w/ allocator
{
using Expect = std::basic_string<char, std::char_traits<char>, test_allocator<char>>;
using It = cpp17_input_iterator<const char*>;
const char* input = "abcdef";
std::basic_string s(It(input), It(input + 3), test_allocator<char>{});
ASSERT_SAME_TYPE(decltype(s), Expect);
assert(s == "abc");
}
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
{
using ExpectW = std::basic_string<wchar_t, std::char_traits<wchar_t>, test_allocator<wchar_t>>;
using It = cpp17_input_iterator<const wchar_t*>;
const wchar_t* input = L"abcdef";
std::basic_string s(It(input), It(input + 3), test_allocator<wchar_t>{});
ASSERT_SAME_TYPE(decltype(s), ExpectW);
assert(s == L"abc");
}
#endif
}
{ // Testing (9)
const std::string sin("abc");
std::basic_string s(sin);
ASSERT_SAME_TYPE(decltype(s), std::string);
assert(s == "abc");
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
using WStr = std::basic_string<wchar_t,
constexpr_char_traits<wchar_t>,
test_allocator<wchar_t>>;
const WStr win(L"abcdef");
std::basic_string w(win);
ASSERT_SAME_TYPE(decltype(w), WStr);
assert(w == L"abcdef");
#endif
}
{ // Testing (10)
const std::string sin("abc");
std::basic_string s(sin, std::allocator<char>{});
ASSERT_SAME_TYPE(decltype(s), std::string);
assert(s == "abc");
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
using WStr = std::basic_string<wchar_t,
constexpr_char_traits<wchar_t>,
test_allocator<wchar_t>>;
const WStr win(L"abcdef");
std::basic_string w(win, test_allocator<wchar_t>{});
ASSERT_SAME_TYPE(decltype(w), WStr);
assert(w == L"abcdef");
#endif
}
{ // Testing (11)
std::string sin("abc");
std::basic_string s(std::move(sin));
ASSERT_SAME_TYPE(decltype(s), std::string);
assert(s == "abc");
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
using WStr = std::basic_string<wchar_t,
constexpr_char_traits<wchar_t>,
test_allocator<wchar_t>>;
WStr win(L"abcdef");
std::basic_string w(std::move(win));
ASSERT_SAME_TYPE(decltype(w), WStr);
assert(w == L"abcdef");
#endif
}
{ // Testing (12)
std::string sin("abc");
std::basic_string s(std::move(sin), std::allocator<char>{});
ASSERT_SAME_TYPE(decltype(s), std::string);
assert(s == "abc");
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
using WStr = std::basic_string<wchar_t,
constexpr_char_traits<wchar_t>,
test_allocator<wchar_t>>;
WStr win(L"abcdef");
std::basic_string w(std::move(win), test_allocator<wchar_t>{});
ASSERT_SAME_TYPE(decltype(w), WStr);
assert(w == L"abcdef");
#endif
}
{ // Testing (13) w/o allocator
std::basic_string s({'a', 'b', 'c'});
ASSERT_SAME_TYPE(decltype(s), std::string);
assert(s == "abc");
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
std::basic_string w({L'a', L'b', L'c'});
ASSERT_SAME_TYPE(decltype(w), std::wstring);
assert(w == L"abc");
#endif
}
{ // Testing (13) w/ allocator
std::basic_string s({'a', 'b', 'c'}, test_allocator<char>{});
ASSERT_SAME_TYPE(decltype(s), BStr<char, test_allocator<char>>);
assert(s == "abc");
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
std::basic_string w({L'a', L'b', L'c'}, test_allocator<wchar_t>{});
ASSERT_SAME_TYPE(decltype(w), BStr<wchar_t, test_allocator<wchar_t>>);
assert(w == L"abc");
#endif
}
{ // Testing (14) w/o allocator
std::string_view sv("abc");
std::basic_string s(sv);
ASSERT_SAME_TYPE(decltype(s), std::string);
assert(s == "abc");
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
using Expect = std::basic_string<wchar_t, constexpr_char_traits<wchar_t>>;
std::basic_string_view<wchar_t, constexpr_char_traits<wchar_t>> BSV(L"abcdef");
std::basic_string w(BSV);
ASSERT_SAME_TYPE(decltype(w), Expect);
assert(w == L"abcdef");
#endif
}
{ // Testing (14) w/ allocator
using ExpectS = std::basic_string<char, std::char_traits<char>, test_allocator<char>>;
std::string_view sv("abc");
std::basic_string s(sv, test_allocator<char>{});
ASSERT_SAME_TYPE(decltype(s), ExpectS);
assert(s == "abc");
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
using ExpectW = std::basic_string<wchar_t, constexpr_char_traits<wchar_t>,
test_allocator<wchar_t>>;
std::basic_string_view<wchar_t, constexpr_char_traits<wchar_t>> BSV(L"abcdef");
std::basic_string w(BSV, test_allocator<wchar_t>{});
ASSERT_SAME_TYPE(decltype(w), ExpectW);
assert(w == L"abcdef");
#endif
}
{ // Testing (15) w/o allocator
std::string s0("abc");
std::basic_string s(s0, 1, 1);
ASSERT_SAME_TYPE(decltype(s), std::string);
assert(s == "b");
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
std::wstring w0(L"abcdef");
std::basic_string w(w0, 2, 2);
ASSERT_SAME_TYPE(decltype(w), std::wstring);
assert(w == L"cd");
#endif
}
{ // Testing (15) w/ allocator
using ExpectS = std::basic_string<char, std::char_traits<char>, test_allocator<char>>;
ExpectS s0("abc");
std::basic_string s(s0, 1, 1, test_allocator<char>{4});
ASSERT_SAME_TYPE(decltype(s), ExpectS);
assert(s == "b");
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
using ExpectW = std::basic_string<wchar_t, std::char_traits<wchar_t>, test_allocator<wchar_t>>;
ExpectW w0(L"abcdef");
std::basic_string w(w0, 2, 2, test_allocator<wchar_t>{6});
ASSERT_SAME_TYPE(decltype(w), ExpectW);
assert(w == L"cd");
#endif
}
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
static_assert(test());
#endif
return 0;
}
@@ -0,0 +1,59 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// <string>
// basic_string(initializer_list<charT> il, const Allocator& a = Allocator()); // constexpr since C++20
#include <string>
#include <cassert>
#include "test_macros.h"
#include "test_allocator.h"
#include "min_allocator.h"
TEST_CONSTEXPR_CXX20 bool test() {
{
std::string s = {'a', 'b', 'c'};
assert(s == "abc");
}
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
{
std::wstring s;
s = {L'a', L'b', L'c'};
assert(s == L"abc");
}
#endif
{
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
S s = {'a', 'b', 'c'};
assert(s == "abc");
}
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
{
typedef std::basic_string<wchar_t, std::char_traits<wchar_t>, min_allocator<wchar_t>> S;
S s;
s = {L'a', L'b', L'c'};
assert(s == L"abc");
}
#endif
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
static_assert(test());
#endif
return 0;
}
@@ -0,0 +1,45 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// <string>
// basic_string& operator=(initializer_list<charT> il); // constexpr since C++20
#include <string>
#include <cassert>
#include "test_macros.h"
#include "min_allocator.h"
TEST_CONSTEXPR_CXX20 bool test() {
{
std::string s;
s = {'a', 'b', 'c'};
assert(s == "abc");
}
{
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
S s;
s = {'a', 'b', 'c'};
assert(s == "abc");
}
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
static_assert(test());
#endif
return 0;
}
@@ -0,0 +1,145 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <string>
// template<class InputIterator>
// basic_string(InputIterator begin, InputIterator end,
// const Allocator& a = Allocator()); // constexpr since C++20
#include <string>
#include <iterator>
#include <cassert>
#include <cstddef>
#include "test_macros.h"
#include "test_allocator.h"
#include "test_iterators.h"
#include "min_allocator.h"
template <class It>
TEST_CONSTEXPR_CXX20 void
test(It first, It last)
{
typedef typename std::iterator_traits<It>::value_type charT;
typedef std::basic_string<charT, std::char_traits<charT>, test_allocator<charT> > S;
typedef typename S::allocator_type A;
S s2(first, last);
LIBCPP_ASSERT(s2.__invariants());
assert(s2.size() == static_cast<std::size_t>(std::distance(first, last)));
unsigned i = 0;
for (It it = first; it != last;) {
assert(s2[i] == *it);
++it;
++i;
}
assert(s2.get_allocator() == A());
assert(s2.capacity() >= s2.size());
}
template <class It, class A>
TEST_CONSTEXPR_CXX20 void
test(It first, It last, const A& a)
{
typedef typename std::iterator_traits<It>::value_type charT;
typedef std::basic_string<charT, std::char_traits<charT>, A> S;
S s2(first, last, a);
LIBCPP_ASSERT(s2.__invariants());
assert(s2.size() == static_cast<std::size_t>(std::distance(first, last)));
unsigned i = 0;
for (It it = first; it != last;) {
assert(s2[i] == *it);
++it;
++i;
}
assert(s2.get_allocator() == a);
assert(s2.capacity() >= s2.size());
}
TEST_CONSTEXPR_CXX20 bool test() {
{
typedef test_allocator<char> A;
const char* s = "12345678901234567890123456789012345678901234567890";
test(s, s);
test(s, s, A(2));
test(s, s+1);
test(s, s+1, A(2));
test(s, s+10);
test(s, s+10, A(2));
test(s, s+50);
test(s, s+50, A(2));
test(cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s));
test(cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s), A(2));
test(cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1));
test(cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1), A(2));
test(cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10));
test(cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10), A(2));
test(cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+50));
test(cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+50), A(2));
}
#if TEST_STD_VER >= 11
{
typedef min_allocator<char> A;
const char* s = "12345678901234567890123456789012345678901234567890";
test(s, s);
test(s, s, A());
test(s, s+1);
test(s, s+1, A());
test(s, s+10);
test(s, s+10, A());
test(s, s+50);
test(s, s+50, A());
test(cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s));
test(cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s), A());
test(cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1));
test(cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1), A());
test(cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10));
test(cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10), A());
test(cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+50));
test(cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+50), A());
}
#endif
{
static_assert((!std::is_constructible<std::string, std::string,
std::string>::value),
"");
static_assert(
(!std::is_constructible<std::string, std::string, std::string,
std::allocator<char> >::value),
"");
}
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
static_assert(test());
#endif
return 0;
}
@@ -0,0 +1,115 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <string>
// UNSUPPORTED: c++03, c++11, c++14
// template<class InputIterator,
// class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
// basic_string(InputIterator, InputIterator, Allocator = Allocator())
// -> basic_string<typename iterator_traits<InputIterator>::value_type,
// char_traits<typename iterator_traits<InputIterator>::value_type>,
// Allocator>; // constexpr since C++20
//
// The deduction guide shall not participate in overload resolution if InputIterator
// is a type that does not qualify as an input iterator, or if Allocator is a type
// that does not qualify as an allocator.
#include <cassert>
#include <cstddef>
#include <iterator>
#include <string>
#include <type_traits>
#include "test_macros.h"
#include "test_allocator.h"
#include "min_allocator.h"
class NotAnIterator {};
using NotAnInputIterator = std::back_insert_iterator<std::basic_string<char16_t>>;
template <typename T>
struct NotAnAllocator { typedef T value_type; };
template <class Iter, class Alloc, class = void>
struct CanDeduce : std::false_type { };
template <class Iter, class Alloc>
struct CanDeduce<Iter, Alloc, decltype((void)
std::basic_string{std::declval<Iter>(), std::declval<Iter>(), std::declval<Alloc>()}
)> : std::true_type { };
static_assert( CanDeduce<int*, std::allocator<int>>::value);
static_assert(!CanDeduce<NotAnIterator, std::allocator<char>>::value);
static_assert(!CanDeduce<NotAnInputIterator, std::allocator<char16_t>>::value);
static_assert(!CanDeduce<wchar_t const*, NotAnAllocator<wchar_t>>::value);
TEST_CONSTEXPR_CXX20 bool test() {
{
const char* s = "12345678901234";
std::basic_string s1(s, s+10); // Can't use {} here
using S = decltype(s1); // what type did we get?
static_assert(std::is_same_v<S::value_type, char>, "");
static_assert(std::is_same_v<S::traits_type, std::char_traits<char>>, "");
static_assert(std::is_same_v<S::allocator_type, std::allocator<char>>, "");
assert(s1.size() == 10);
assert(s1.compare(0, s1.size(), s, s1.size()) == 0);
}
{
const char* s = "12345678901234";
std::basic_string s1{s, s+10, std::allocator<char>{}};
using S = decltype(s1); // what type did we get?
static_assert(std::is_same_v<S::value_type, char>, "");
static_assert(std::is_same_v<S::traits_type, std::char_traits<char>>, "");
static_assert(std::is_same_v<S::allocator_type, std::allocator<char>>, "");
assert(s1.size() == 10);
assert(s1.compare(0, s1.size(), s, s1.size()) == 0);
}
{
const wchar_t* s = L"12345678901234";
std::basic_string s1{s, s+10, test_allocator<wchar_t>{}};
using S = decltype(s1); // what type did we get?
static_assert(std::is_same_v<S::value_type, wchar_t>, "");
static_assert(std::is_same_v<S::traits_type, std::char_traits<wchar_t>>, "");
static_assert(std::is_same_v<S::allocator_type, test_allocator<wchar_t>>, "");
assert(s1.size() == 10);
assert(s1.compare(0, s1.size(), s, s1.size()) == 0);
}
{
const char16_t* s = u"12345678901234";
std::basic_string s1{s, s+10, min_allocator<char16_t>{}};
using S = decltype(s1); // what type did we get?
static_assert(std::is_same_v<S::value_type, char16_t>, "");
static_assert(std::is_same_v<S::traits_type, std::char_traits<char16_t>>, "");
static_assert(std::is_same_v<S::allocator_type, min_allocator<char16_t>>, "");
assert(s1.size() == 10);
assert(s1.compare(0, s1.size(), s, s1.size()) == 0);
}
{
const char32_t* s = U"12345678901234";
std::basic_string s1{s, s+10, explicit_allocator<char32_t>{}};
using S = decltype(s1); // what type did we get?
static_assert(std::is_same_v<S::value_type, char32_t>, "");
static_assert(std::is_same_v<S::traits_type, std::char_traits<char32_t>>, "");
static_assert(std::is_same_v<S::allocator_type, explicit_allocator<char32_t>>, "");
assert(s1.size() == 10);
assert(s1.compare(0, s1.size(), s, s1.size()) == 0);
}
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
static_assert(test());
#endif
return 0;
}
@@ -0,0 +1,62 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// <string>
// basic_string(basic_string<charT,traits,Allocator>&& str); // constexpr since C++20
#include <string>
#include <cassert>
#include "test_macros.h"
#include "test_allocator.h"
#include "min_allocator.h"
template <class S>
TEST_CONSTEXPR_CXX20 void
test(S s0)
{
S s1 = s0;
S s2 = std::move(s0);
LIBCPP_ASSERT(s2.__invariants());
LIBCPP_ASSERT(s0.__invariants());
assert(s2 == s1);
assert(s2.capacity() >= s2.size());
assert(s2.get_allocator() == s1.get_allocator());
}
TEST_CONSTEXPR_CXX20 bool test() {
{
typedef test_allocator<char> A;
typedef std::basic_string<char, std::char_traits<char>, A> S;
test(S(A(3)));
test(S("1", A(5)));
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)));
}
{
typedef min_allocator<char> A;
typedef std::basic_string<char, std::char_traits<char>, A> S;
test(S(A{}));
test(S("1", A()));
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()));
}
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
static_assert(test());
#endif
return 0;
}
@@ -0,0 +1,87 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// <string>
// basic_string(basic_string&& str, const Allocator& alloc); // constexpr since C++20
#include <string>
#include <cassert>
#include "test_macros.h"
#include "test_allocator.h"
#include "min_allocator.h"
template <class S>
TEST_CONSTEXPR_CXX20 void
test(S s0, const typename S::allocator_type& a)
{
S s1 = s0;
S s2(std::move(s0), a);
LIBCPP_ASSERT(s2.__invariants());
LIBCPP_ASSERT(s0.__invariants());
assert(s2 == s1);
assert(s2.capacity() >= s2.size());
assert(s2.get_allocator() == a);
}
TEST_CONSTEXPR_CXX20 bool test() {
test_allocator_statistics alloc_stats;
{
typedef test_allocator<char> A;
typedef std::basic_string<char, std::char_traits<char>, A> S;
#if TEST_STD_VER > 14
static_assert((noexcept(S{})), "" );
#elif TEST_STD_VER >= 11
static_assert((noexcept(S()) == std::is_nothrow_move_constructible<A>::value), "" );
#endif
test(S(), A(3, &alloc_stats));
test(S("1"), A(5, &alloc_stats));
test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), A(7, &alloc_stats));
}
int alloc_count = alloc_stats.alloc_count;
{
typedef test_allocator<char> A;
typedef std::basic_string<char, std::char_traits<char>, A> S;
#if TEST_STD_VER > 14
static_assert((noexcept(S{})), "" );
#elif TEST_STD_VER >= 11
static_assert((noexcept(S()) == std::is_nothrow_move_constructible<A>::value), "" );
#endif
S s1 ( "Twas brillig, and the slivy toves did gyre and gymbal in the wabe", A(&alloc_stats));
S s2 (std::move(s1), A(1, &alloc_stats));
}
assert ( alloc_stats.alloc_count == alloc_count );
{
typedef min_allocator<char> A;
typedef std::basic_string<char, std::char_traits<char>, A> S;
#if TEST_STD_VER > 14
static_assert((noexcept(S{})), "" );
#elif TEST_STD_VER >= 11
static_assert((noexcept(S()) == std::is_nothrow_move_constructible<A>::value), "" );
#endif
test(S(), A());
test(S("1"), A());
test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), A());
}
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
static_assert(test());
#endif
return 0;
}
@@ -0,0 +1,107 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// <string>
// basic_string& operator=(basic_string&& c)
// noexcept(
// allocator_traits<allocator_type>::propagate_on_container_move_assignment::value ||
// allocator_traits<allocator_type>::is_always_equal::value); // C++17, constexpr since C++20
//
// before C++17, we use the conforming extension
// noexcept(
// allocator_type::propagate_on_container_move_assignment::value &&
// is_nothrow_move_assignable<allocator_type>::value); // constexpr since C++20
#include <string>
#include <cassert>
#include "test_macros.h"
#include "test_allocator.h"
template <class T>
struct some_alloc
{
typedef T value_type;
some_alloc(const some_alloc&);
T *allocate(size_t);
};
template <class T>
struct some_alloc2
{
typedef T value_type;
some_alloc2() {}
some_alloc2(const some_alloc2&);
T *allocate(size_t);
void deallocate(void*, unsigned) {}
typedef std::false_type propagate_on_container_move_assignment;
typedef std::true_type is_always_equal;
};
template <class T>
struct some_alloc3
{
typedef T value_type;
some_alloc3() {}
some_alloc3(const some_alloc3&);
T *allocate(size_t);
void deallocate(void*, unsigned) {}
typedef std::false_type propagate_on_container_move_assignment;
typedef std::false_type is_always_equal;
};
TEST_CONSTEXPR_CXX20 bool test() {
{
typedef std::string C;
static_assert(std::is_nothrow_move_assignable<C>::value, "");
}
{
typedef std::basic_string<char, std::char_traits<char>, test_allocator<char>> C;
static_assert(!std::is_nothrow_move_assignable<C>::value, "");
}
{
typedef std::basic_string<char, std::char_traits<char>, some_alloc<char>> C;
#if TEST_STD_VER > 14
// if the allocators are always equal, then the move assignment can be noexcept
static_assert( std::is_nothrow_move_assignable<C>::value, "");
#else
static_assert(!std::is_nothrow_move_assignable<C>::value, "");
#endif
}
#if TEST_STD_VER > 14
{
// POCMA is false, always equal
typedef std::basic_string<char, std::char_traits<char>, some_alloc2<char>> C;
static_assert( std::is_nothrow_move_assignable<C>::value, "");
}
{
// POCMA is false, not always equal
typedef std::basic_string<char, std::char_traits<char>, some_alloc3<char>> C;
static_assert(!std::is_nothrow_move_assignable<C>::value, "");
}
#endif
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
static_assert(test());
#endif
return 0;
}
@@ -0,0 +1,84 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// <string>
// basic_string<charT,traits,Allocator>&
// operator=(basic_string<charT,traits,Allocator>&& str); // constexpr since C++20
#include <string>
#include <cassert>
#include "test_macros.h"
#include "test_allocator.h"
#include "min_allocator.h"
template <class S>
TEST_CONSTEXPR_CXX20 void
test(S s1, S s2)
{
S s0 = s2;
s1 = std::move(s2);
LIBCPP_ASSERT(s1.__invariants());
LIBCPP_ASSERT(s2.__invariants());
assert(s1 == s0);
assert(s1.capacity() >= s1.size());
}
TEST_CONSTEXPR_CXX20 bool test() {
{
typedef std::string S;
test(S(), S());
test(S("1"), S());
test(S(), S("1"));
test(S("1"), S("2"));
test(S("1"), S("2"));
test(S(),
S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
test(S("123456789"),
S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
test(S("1234567890123456789012345678901234567890123456789012345678901234567890"),
S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
test(S("1234567890123456789012345678901234567890123456789012345678901234567890"
"1234567890123456789012345678901234567890123456789012345678901234567890"),
S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
}
{
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
test(S(), S());
test(S("1"), S());
test(S(), S("1"));
test(S("1"), S("2"));
test(S("1"), S("2"));
test(S(),
S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
test(S("123456789"),
S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
test(S("1234567890123456789012345678901234567890123456789012345678901234567890"),
S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
test(S("1234567890123456789012345678901234567890123456789012345678901234567890"
"1234567890123456789012345678901234567890123456789012345678901234567890"),
S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
}
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
static_assert(test());
#endif
return 0;
}
@@ -0,0 +1,44 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03
// <string>
// basic_string(basic_string&&)
// noexcept(is_nothrow_move_constructible<allocator_type>::value); // constexpr since C++20
// This tests a conforming extension
#include <string>
#include <cassert>
#include "test_macros.h"
#include "test_allocator.h"
int main(int, char**)
{
{
typedef std::string C;
static_assert(std::is_nothrow_move_constructible<C>::value, "");
}
{
typedef std::basic_string<char, std::char_traits<char>, test_allocator<char>> C;
static_assert(std::is_nothrow_move_constructible<C>::value, "");
}
{
typedef std::basic_string<char, std::char_traits<char>, limited_allocator<char, 10>> C;
#if TEST_STD_VER <= 14
static_assert(!std::is_nothrow_move_constructible<C>::value, "");
#else
static_assert( std::is_nothrow_move_constructible<C>::value, "");
#endif
}
return 0;
}
@@ -0,0 +1,21 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
// <string>
// basic_string(nullptr_t) = delete; // C++2b
// basic_string& operator=(nullptr_t) = delete; // C++2b
#include <string>
#include <type_traits>
static_assert(!std::is_convertible_v<decltype(nullptr), std::string>);
static_assert(!std::is_constructible_v<std::string, decltype(nullptr)>);
static_assert(!std::is_assignable_v<std::string, decltype(nullptr)>);
@@ -0,0 +1,99 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <string>
// basic_string(const charT* s, const Allocator& a = Allocator()); // constexpr since C++20
#include <string>
#include <stdexcept>
#include <algorithm>
#include <cassert>
#include <cstddef>
#include "test_macros.h"
#include "test_allocator.h"
#include "min_allocator.h"
template <class charT>
TEST_CONSTEXPR_CXX20 void
test(const charT* s)
{
typedef std::basic_string<charT, std::char_traits<charT>, test_allocator<charT> > S;
typedef typename S::traits_type T;
typedef typename S::allocator_type A;
std::size_t n = T::length(s);
S s2(s);
LIBCPP_ASSERT(s2.__invariants());
assert(s2.size() == n);
assert(T::compare(s2.data(), s, n) == 0);
assert(s2.get_allocator() == A());
assert(s2.capacity() >= s2.size());
}
template <class charT, class A>
TEST_CONSTEXPR_CXX20 void
test(const charT* s, const A& a)
{
typedef std::basic_string<charT, std::char_traits<charT>, A> S;
typedef typename S::traits_type T;
std::size_t n = T::length(s);
S s2(s, a);
LIBCPP_ASSERT(s2.__invariants());
assert(s2.size() == n);
assert(T::compare(s2.data(), s, n) == 0);
assert(s2.get_allocator() == a);
assert(s2.capacity() >= s2.size());
}
TEST_CONSTEXPR_CXX20 bool test() {
{
typedef test_allocator<char> A;
test("");
test("", A(2));
test("1");
test("1", A(2));
test("1234567980");
test("1234567980", A(2));
test("123456798012345679801234567980123456798012345679801234567980");
test("123456798012345679801234567980123456798012345679801234567980", A(2));
}
#if TEST_STD_VER >= 11
{
typedef min_allocator<char> A;
test("");
test("", A());
test("1");
test("1", A());
test("1234567980");
test("1234567980", A());
test("123456798012345679801234567980123456798012345679801234567980");
test("123456798012345679801234567980123456798012345679801234567980", A());
}
#endif
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
static_assert(test());
#endif
return 0;
}
@@ -0,0 +1,83 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <string>
// basic_string<charT,traits,Allocator>&
// operator=(const charT* s); // constexpr since C++20
#include <string>
#include <cassert>
#include "test_macros.h"
#include "min_allocator.h"
template <class S>
TEST_CONSTEXPR_CXX20 void
test(S s1, const typename S::value_type* s2)
{
typedef typename S::traits_type T;
s1 = s2;
LIBCPP_ASSERT(s1.__invariants());
assert(s1.size() == T::length(s2));
assert(T::compare(s1.data(), s2, s1.size()) == 0);
assert(s1.capacity() >= s1.size());
}
TEST_CONSTEXPR_CXX20 bool test() {
{
typedef std::string S;
test(S(), "");
test(S("1"), "");
test(S(), "1");
test(S("1"), "2");
test(S("1"), "2");
test(S(),
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
test(S("123456789"),
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
test(S("1234567890123456789012345678901234567890123456789012345678901234567890"),
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
test(S("1234567890123456789012345678901234567890123456789012345678901234567890"
"1234567890123456789012345678901234567890123456789012345678901234567890"),
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
}
#if TEST_STD_VER >= 11
{
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
test(S(), "");
test(S("1"), "");
test(S(), "1");
test(S("1"), "2");
test(S("1"), "2");
test(S(),
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
test(S("123456789"),
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
test(S("1234567890123456789012345678901234567890123456789012345678901234567890"),
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
test(S("1234567890123456789012345678901234567890123456789012345678901234567890"
"1234567890123456789012345678901234567890123456789012345678901234567890"),
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
}
#endif
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
static_assert(test());
#endif
return 0;
}
@@ -0,0 +1,104 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <string>
// basic_string(const charT* s, size_type n, const Allocator& a = Allocator()); // constexpr since C++20
#include <string>
#include <stdexcept>
#include <algorithm>
#include <cassert>
#include "test_macros.h"
#include "test_allocator.h"
#include "min_allocator.h"
template <class charT>
TEST_CONSTEXPR_CXX20 void
test(const charT* s, unsigned n)
{
typedef std::basic_string<charT, std::char_traits<charT>, test_allocator<charT> > S;
typedef typename S::traits_type T;
typedef typename S::allocator_type A;
S s2(s, n);
LIBCPP_ASSERT(s2.__invariants());
assert(s2.size() == n);
assert(T::compare(s2.data(), s, n) == 0);
assert(s2.get_allocator() == A());
assert(s2.capacity() >= s2.size());
}
template <class charT, class A>
TEST_CONSTEXPR_CXX20 void
test(const charT* s, unsigned n, const A& a)
{
typedef std::basic_string<charT, std::char_traits<charT>, A> S;
typedef typename S::traits_type T;
S s2(s, n, a);
LIBCPP_ASSERT(s2.__invariants());
assert(s2.size() == n);
assert(T::compare(s2.data(), s, n) == 0);
assert(s2.get_allocator() == a);
assert(s2.capacity() >= s2.size());
}
TEST_CONSTEXPR_CXX20 bool test() {
{
typedef test_allocator<char> A;
test("", 0);
test("", 0, A(2));
test("1", 1);
test("1", 1, A(2));
test("1234567980", 10);
test("1234567980", 10, A(2));
test("123456798012345679801234567980123456798012345679801234567980", 60);
test("123456798012345679801234567980123456798012345679801234567980", 60, A(2));
}
#if TEST_STD_VER >= 11
{
typedef min_allocator<char> A;
test("", 0);
test("", 0, A());
test("1", 1);
test("1", 1, A());
test("1234567980", 10);
test("1234567980", 10, A());
test("123456798012345679801234567980123456798012345679801234567980", 60);
test("123456798012345679801234567980123456798012345679801234567980", 60, A());
}
#endif
#if TEST_STD_VER > 3
{ // LWG 2946
std::string s({"abc", 1});
assert(s.size() == 1);
assert(s == "a");
}
#endif
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
static_assert(test());
#endif
return 0;
}
@@ -0,0 +1,134 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <string>
// basic_string(size_type n, charT c, const Allocator& a = Allocator()); // constexpr since C++20
#include <string>
#include <stdexcept>
#include <algorithm>
#include <cassert>
#include <cstddef>
#include "test_macros.h"
#include "test_allocator.h"
#include "min_allocator.h"
template <class charT>
TEST_CONSTEXPR_CXX20 void
test(unsigned n, charT c)
{
typedef std::basic_string<charT, std::char_traits<charT>, test_allocator<charT> > S;
typedef typename S::allocator_type A;
S s2(n, c);
LIBCPP_ASSERT(s2.__invariants());
assert(s2.size() == n);
for (unsigned i = 0; i < n; ++i)
assert(s2[i] == c);
assert(s2.get_allocator() == A());
assert(s2.capacity() >= s2.size());
}
template <class charT, class A>
TEST_CONSTEXPR_CXX20 void
test(unsigned n, charT c, const A& a)
{
typedef std::basic_string<charT, std::char_traits<charT>, A> S;
S s2(n, c, a);
LIBCPP_ASSERT(s2.__invariants());
assert(s2.size() == n);
for (unsigned i = 0; i < n; ++i)
assert(s2[i] == c);
assert(s2.get_allocator() == a);
assert(s2.capacity() >= s2.size());
}
template <class Tp>
TEST_CONSTEXPR_CXX20 void
test(Tp n, Tp c)
{
typedef char charT;
typedef std::basic_string<charT, std::char_traits<charT>, test_allocator<charT> > S;
typedef typename S::allocator_type A;
S s2(n, c);
LIBCPP_ASSERT(s2.__invariants());
assert(s2.size() == static_cast<std::size_t>(n));
for (int i = 0; i < n; ++i)
assert(s2[i] == c);
assert(s2.get_allocator() == A());
assert(s2.capacity() >= s2.size());
}
template <class Tp, class A>
TEST_CONSTEXPR_CXX20 void
test(Tp n, Tp c, const A& a)
{
typedef char charT;
typedef std::basic_string<charT, std::char_traits<charT>, A> S;
S s2(n, c, a);
LIBCPP_ASSERT(s2.__invariants());
assert(s2.size() == static_cast<std::size_t>(n));
for (int i = 0; i < n; ++i)
assert(s2[i] == c);
assert(s2.get_allocator() == a);
assert(s2.capacity() >= s2.size());
}
TEST_CONSTEXPR_CXX20 bool test() {
{
typedef test_allocator<char> A;
test(0, 'a');
test(0, 'a', A(2));
test(1, 'a');
test(1, 'a', A(2));
test(10, 'a');
test(10, 'a', A(2));
test(100, 'a');
test(100, 'a', A(2));
test(static_cast<char>(100), static_cast<char>(65));
test(static_cast<char>(100), static_cast<char>(65), A(3));
}
#if TEST_STD_VER >= 11
{
typedef min_allocator<char> A;
test(0, 'a');
test(0, 'a', A());
test(1, 'a');
test(1, 'a', A());
test(10, 'a');
test(10, 'a', A());
test(100, 'a');
test(100, 'a', A());
test(static_cast<char>(100), static_cast<char>(65));
test(static_cast<char>(100), static_cast<char>(65), A());
}
#endif
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
static_assert(test());
#endif
return 0;
}
@@ -0,0 +1,125 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <string>
// explicit basic_string(basic_string_view<CharT, traits> sv, const Allocator& a = Allocator()); // constexpr since C++20
#include <algorithm>
#include <cassert>
#include <stdexcept>
#include <string_view>
#include <string>
#include <type_traits>
#include "min_allocator.h"
#include "test_allocator.h"
#include "test_macros.h"
static_assert(!std::is_convertible<std::string_view, std::string const&>::value, "");
static_assert(!std::is_convertible<std::string_view, std::string>::value, "");
template <class charT>
TEST_CONSTEXPR_CXX20 void
test(std::basic_string_view<charT> sv)
{
typedef std::basic_string<charT, std::char_traits<charT>, test_allocator<charT> > S;
typedef typename S::traits_type T;
typedef typename S::allocator_type A;
{
S s2(sv);
LIBCPP_ASSERT(s2.__invariants());
assert(s2.size() == sv.size());
assert(T::compare(s2.data(), sv.data(), sv.size()) == 0);
assert(s2.get_allocator() == A());
assert(s2.capacity() >= s2.size());
}
{
S s2;
s2 = sv;
LIBCPP_ASSERT(s2.__invariants());
assert(s2.size() == sv.size());
assert(T::compare(s2.data(), sv.data(), sv.size()) == 0);
assert(s2.get_allocator() == A());
assert(s2.capacity() >= s2.size());
}
}
template <class charT, class A>
TEST_CONSTEXPR_CXX20 void
test(std::basic_string_view<charT> sv, const A& a)
{
typedef std::basic_string<charT, std::char_traits<charT>, A> S;
typedef typename S::traits_type T;
{
S s2(sv, a);
LIBCPP_ASSERT(s2.__invariants());
assert(s2.size() == sv.size());
assert(T::compare(s2.data(), sv.data(), sv.size()) == 0);
assert(s2.get_allocator() == a);
assert(s2.capacity() >= s2.size());
}
{
S s2(a);
s2 = sv;
LIBCPP_ASSERT(s2.__invariants());
assert(s2.size() == sv.size());
assert(T::compare(s2.data(), sv.data(), sv.size()) == 0);
assert(s2.get_allocator() == a);
assert(s2.capacity() >= s2.size());
}
}
TEST_CONSTEXPR_CXX20 bool test() {
{
typedef test_allocator<char> A;
typedef std::basic_string_view<char, std::char_traits<char> > SV;
test(SV(""));
test(SV(""), A(2));
test(SV("1"));
test(SV("1") ,A(2));
test(SV("1234567980"));
test(SV("1234567980"), A(2));
test(SV("123456798012345679801234567980123456798012345679801234567980"));
test(SV("123456798012345679801234567980123456798012345679801234567980"), A(2));
}
#if TEST_STD_VER >= 11
{
typedef min_allocator<char> A;
typedef std::basic_string_view<char, std::char_traits<char> > SV;
test(SV(""));
test(SV(""), A());
test(SV("1"));
test(SV("1") ,A());
test(SV("1234567980"));
test(SV("1234567980"), A());
test(SV("123456798012345679801234567980123456798012345679801234567980"));
test(SV("123456798012345679801234567980123456798012345679801234567980"), A());
}
#endif
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
static_assert(test());
#endif
return 0;
}
@@ -0,0 +1,84 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <string>
// basic_string<charT,traits,Allocator>& operator=(basic_string_view<charT, traits> sv); // constexpr since C++20
#include <string>
#include <cassert>
#include "test_macros.h"
#include "min_allocator.h"
template <class S, class SV>
TEST_CONSTEXPR_CXX20 void
test(S s1, SV sv)
{
typedef typename S::traits_type T;
s1 = sv;
LIBCPP_ASSERT(s1.__invariants());
assert(s1.size() == sv.size());
assert(T::compare(s1.data(), sv.data(), s1.size()) == 0);
assert(s1.capacity() >= s1.size());
}
TEST_CONSTEXPR_CXX20 bool test() {
{
typedef std::string S;
typedef std::string_view SV;
test(S(), SV(""));
test(S("1"), SV(""));
test(S(), SV("1"));
test(S("1"), SV("2"));
test(S("1"), SV("2"));
test(S(),
SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
test(S("123456789"),
SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
test(S("1234567890123456789012345678901234567890123456789012345678901234567890"),
SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
test(S("1234567890123456789012345678901234567890123456789012345678901234567890"
"1234567890123456789012345678901234567890123456789012345678901234567890"),
SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
}
#if TEST_STD_VER >= 11
{
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
typedef std::string_view SV;
test(S(), SV(""));
test(S("1"), SV(""));
test(S(), SV("1"));
test(S("1"), SV("2"));
test(S("1"), SV("2"));
test(S(),
SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
test(S("123456789"),
SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
test(S("1234567890123456789012345678901234567890123456789012345678901234567890"),
SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
test(S("1234567890123456789012345678901234567890123456789012345678901234567890"
"1234567890123456789012345678901234567890123456789012345678901234567890"),
SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
}
#endif
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
static_assert(test());
#endif
return 0;
}
@@ -0,0 +1,124 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <string>
// UNSUPPORTED: c++03, c++11, c++14
// template<class charT,
// class traits,
// class Allocator = allocator<charT>
// >
// basic_string(basic_string_view<charT, traits>, const Allocator& = Allocator())
// -> basic_string<charT, traits, Allocator>;
//
// The deduction guide shall not participate in overload resolution if Allocator
// is a type that does not qualify as an allocator.
#include <string>
#include <string_view>
#include <iterator>
#include <memory>
#include <type_traits>
#include <cassert>
#include <cstddef>
#include "test_macros.h"
#include "test_allocator.h"
#include "min_allocator.h"
template <class StringView, class Allocator, class = void>
struct CanDeduce : std::false_type { };
template <class StringView, class Allocator>
struct CanDeduce<StringView, Allocator, decltype((void)
std::basic_string{std::declval<StringView>(), std::declval<Allocator>()}
)> : std::true_type { };
struct NotAnAllocator { };
static_assert( CanDeduce<std::string_view, std::allocator<char>>::value);
static_assert(!CanDeduce<std::string_view, NotAnAllocator>::value);
TEST_CONSTEXPR_CXX20 bool test() {
{
std::string_view sv = "12345678901234";
std::basic_string s1(sv);
using S = decltype(s1); // what type did we get?
static_assert(std::is_same_v<S::value_type, char>, "");
static_assert(std::is_same_v<S::traits_type, std::char_traits<char>>, "");
static_assert(std::is_same_v<S::allocator_type, std::allocator<char>>, "");
assert(s1.size() == sv.size());
assert(s1.compare(0, s1.size(), sv.data(), s1.size()) == 0);
}
{
std::string_view sv = "12345678901234";
std::basic_string s1{sv, std::allocator<char>{}};
using S = decltype(s1); // what type did we get?
static_assert(std::is_same_v<S::value_type, char>, "");
static_assert(std::is_same_v<S::traits_type, std::char_traits<char>>, "");
static_assert(std::is_same_v<S::allocator_type, std::allocator<char>>, "");
assert(s1.size() == sv.size());
assert(s1.compare(0, s1.size(), sv.data(), s1.size()) == 0);
}
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
{
std::wstring_view sv = L"12345678901234";
std::basic_string s1{sv, test_allocator<wchar_t>{}};
using S = decltype(s1); // what type did we get?
static_assert(std::is_same_v<S::value_type, wchar_t>, "");
static_assert(std::is_same_v<S::traits_type, std::char_traits<wchar_t>>, "");
static_assert(std::is_same_v<S::allocator_type, test_allocator<wchar_t>>, "");
assert(s1.size() == sv.size());
assert(s1.compare(0, s1.size(), sv.data(), s1.size()) == 0);
}
#endif
#ifndef TEST_HAS_NO_CHAR8_T
{
std::u8string_view sv = u8"12345678901234";
std::basic_string s1{sv, min_allocator<char8_t>{}};
using S = decltype(s1); // what type did we get?
static_assert(std::is_same_v<S::value_type, char8_t>, "");
static_assert(std::is_same_v<S::traits_type, std::char_traits<char8_t>>, "");
static_assert(std::is_same_v<S::allocator_type, min_allocator<char8_t>>, "");
assert(s1.size() == sv.size());
assert(s1.compare(0, s1.size(), sv.data(), s1.size()) == 0);
}
#endif
{
std::u16string_view sv = u"12345678901234";
std::basic_string s1{sv, min_allocator<char16_t>{}};
using S = decltype(s1); // what type did we get?
static_assert(std::is_same_v<S::value_type, char16_t>, "");
static_assert(std::is_same_v<S::traits_type, std::char_traits<char16_t>>, "");
static_assert(std::is_same_v<S::allocator_type, min_allocator<char16_t>>, "");
assert(s1.size() == sv.size());
assert(s1.compare(0, s1.size(), sv.data(), s1.size()) == 0);
}
{
std::u32string_view sv = U"12345678901234";
std::basic_string s1{sv, explicit_allocator<char32_t>{}};
using S = decltype(s1); // what type did we get?
static_assert(std::is_same_v<S::value_type, char32_t>, "");
static_assert(std::is_same_v<S::traits_type, std::char_traits<char32_t>>, "");
static_assert(std::is_same_v<S::allocator_type, explicit_allocator<char32_t>>, "");
assert(s1.size() == sv.size());
assert(s1.compare(0, s1.size(), sv.data(), s1.size()) == 0);
}
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
static_assert(test());
#endif
return 0;
}
@@ -0,0 +1,128 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <string>
// UNSUPPORTED: c++03, c++11, c++14
// template<class charT,
// class traits,
// class Allocator = allocator<charT>
// >
// basic_string(basic_string_view<charT, traits>,
// typename see below::size_type,
// typename see below::size_type,
// const Allocator& = Allocator())
// -> basic_string<charT, traits, Allocator>;
//
// A size_type parameter type in a basic_string deduction guide refers to the size_type
// member type of the type deduced by the deduction guide.
//
// The deduction guide shall not participate in overload resolution if Allocator
// is a type that does not qualify as an allocator.
#include <string>
#include <string_view>
#include <iterator>
#include <cassert>
#include <cstddef>
#include "test_macros.h"
#include "test_allocator.h"
#include "min_allocator.h"
template <class StringView, class Size, class Allocator, class = void>
struct CanDeduce : std::false_type { };
template <class StringView, class Size, class Allocator>
struct CanDeduce<StringView, Size, Allocator, decltype((void)
std::basic_string{std::declval<StringView>(), std::declval<Size>(), std::declval<Size>(), std::declval<Allocator>()}
)> : std::true_type { };
struct NotAnAllocator { };
static_assert( CanDeduce<std::string_view, std::size_t, std::allocator<char>>::value);
static_assert(!CanDeduce<std::string_view, std::size_t, NotAnAllocator>::value);
TEST_CONSTEXPR_CXX20 bool test() {
{
std::string_view sv = "12345678901234";
std::basic_string s1{sv, 0, 4};
using S = decltype(s1); // what type did we get?
static_assert(std::is_same_v<S::value_type, char>, "");
static_assert(std::is_same_v<S::traits_type, std::char_traits<char>>, "");
static_assert(std::is_same_v<S::allocator_type, std::allocator<char>>, "");
assert(s1.size() == 4);
assert(s1.compare(0, s1.size(), sv.data(), s1.size()) == 0);
}
{
std::string_view sv = "12345678901234";
std::basic_string s1{sv, 0, 4, std::allocator<char>{}};
using S = decltype(s1); // what type did we get?
static_assert(std::is_same_v<S::value_type, char>, "");
static_assert(std::is_same_v<S::traits_type, std::char_traits<char>>, "");
static_assert(std::is_same_v<S::allocator_type, std::allocator<char>>, "");
assert(s1.size() == 4);
assert(s1.compare(0, s1.size(), sv.data(), s1.size()) == 0);
}
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
{
std::wstring_view sv = L"12345678901234";
std::basic_string s1{sv, 0, 4, test_allocator<wchar_t>{}};
using S = decltype(s1); // what type did we get?
static_assert(std::is_same_v<S::value_type, wchar_t>, "");
static_assert(std::is_same_v<S::traits_type, std::char_traits<wchar_t>>, "");
static_assert(std::is_same_v<S::allocator_type, test_allocator<wchar_t>>, "");
assert(s1.size() == 4);
assert(s1.compare(0, s1.size(), sv.data(), s1.size()) == 0);
}
#endif
#ifndef TEST_HAS_NO_CHAR8_T
{
std::u8string_view sv = u8"12345678901234";
std::basic_string s1{sv, 0, 4, min_allocator<char8_t>{}};
using S = decltype(s1); // what type did we get?
static_assert(std::is_same_v<S::value_type, char8_t>, "");
static_assert(std::is_same_v<S::traits_type, std::char_traits<char8_t>>, "");
static_assert(std::is_same_v<S::allocator_type, min_allocator<char8_t>>, "");
assert(s1.size() == 4);
assert(s1.compare(0, s1.size(), sv.data(), s1.size()) == 0);
}
#endif
{
std::u16string_view sv = u"12345678901234";
std::basic_string s1{sv, 0, 4, min_allocator<char16_t>{}};
using S = decltype(s1); // what type did we get?
static_assert(std::is_same_v<S::value_type, char16_t>, "");
static_assert(std::is_same_v<S::traits_type, std::char_traits<char16_t>>, "");
static_assert(std::is_same_v<S::allocator_type, min_allocator<char16_t>>, "");
assert(s1.size() == 4);
assert(s1.compare(0, s1.size(), sv.data(), s1.size()) == 0);
}
{
std::u32string_view sv = U"12345678901234";
std::basic_string s1{sv, 0, 4, explicit_allocator<char32_t>{}};
using S = decltype(s1); // what type did we get?
static_assert(std::is_same_v<S::value_type, char32_t>, "");
static_assert(std::is_same_v<S::traits_type, std::char_traits<char32_t>>, "");
static_assert(std::is_same_v<S::allocator_type, explicit_allocator<char32_t>>, "");
assert(s1.size() == 4);
assert(s1.compare(0, s1.size(), sv.data(), s1.size()) == 0);
}
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
static_assert(test());
#endif
return 0;
}
@@ -0,0 +1,233 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <string>
// basic_string(const basic_string<charT,traits,Allocator>& str,
// size_type pos, size_type n,
// const Allocator& a = Allocator()); // constexpr since C++20
//
// basic_string(const basic_string<charT,traits,Allocator>& str,
// size_type pos,
// const Allocator& a = Allocator()); // constexpr since C++20
#include <string>
#include <stdexcept>
#include <algorithm>
#include <vector>
#include <scoped_allocator>
#include <cassert>
#include "test_macros.h"
#include "test_allocator.h"
#include "min_allocator.h"
template <class S>
TEST_CONSTEXPR_CXX20 void
test(S str, unsigned pos)
{
typedef typename S::traits_type T;
typedef typename S::allocator_type A;
if (pos <= str.size())
{
S s2(str, pos);
LIBCPP_ASSERT(s2.__invariants());
typename S::size_type rlen = str.size() - pos;
assert(s2.size() == rlen);
assert(T::compare(s2.data(), str.data() + pos, rlen) == 0);
assert(s2.get_allocator() == A());
assert(s2.capacity() >= s2.size());
}
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED)
{
try
{
S s2(str, pos);
assert(false);
}
catch (std::out_of_range&)
{
assert(pos > str.size());
}
}
#endif
}
template <class S>
TEST_CONSTEXPR_CXX20 void
test(S str, unsigned pos, unsigned n)
{
typedef typename S::traits_type T;
typedef typename S::allocator_type A;
if (pos <= str.size())
{
S s2(str, pos, n);
LIBCPP_ASSERT(s2.__invariants());
typename S::size_type rlen = std::min<typename S::size_type>(str.size() - pos, n);
assert(s2.size() == rlen);
assert(T::compare(s2.data(), str.data() + pos, rlen) == 0);
assert(s2.get_allocator() == A());
assert(s2.capacity() >= s2.size());
}
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED)
{
try
{
S s2(str, pos, n);
assert(false);
}
catch (std::out_of_range&)
{
assert(pos > str.size());
}
}
#endif
}
template <class S>
TEST_CONSTEXPR_CXX20 void
test(S str, unsigned pos, unsigned n, const typename S::allocator_type& a)
{
typedef typename S::traits_type T;
if (pos <= str.size())
{
S s2(str, pos, n, a);
LIBCPP_ASSERT(s2.__invariants());
typename S::size_type rlen = std::min<typename S::size_type>(str.size() - pos, n);
assert(s2.size() == rlen);
assert(T::compare(s2.data(), str.data() + pos, rlen) == 0);
assert(s2.get_allocator() == a);
assert(s2.capacity() >= s2.size());
}
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED)
{
try
{
S s2(str, pos, n, a);
assert(false);
}
catch (std::out_of_range&)
{
assert(pos > str.size());
}
}
#endif
}
void test_lwg2583()
{
#if TEST_STD_VER >= 11 && !defined(TEST_HAS_NO_EXCEPTIONS)
typedef std::basic_string<char, std::char_traits<char>, test_allocator<char>> StringA;
std::vector<StringA, std::scoped_allocator_adaptor<test_allocator<StringA>>> vs;
StringA s{"1234"};
vs.emplace_back(s, 2);
try { vs.emplace_back(s, 5); }
catch (const std::out_of_range&) { return; }
assert(false);
#endif
}
TEST_CONSTEXPR_CXX20 bool test() {
{
typedef test_allocator<char> A;
typedef std::basic_string<char, std::char_traits<char>, A> S;
test(S(A(3)), 0);
test(S(A(3)), 1);
test(S("1", A(5)), 0);
test(S("1", A(5)), 1);
test(S("1", A(5)), 2);
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 0);
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 5);
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 50);
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 500);
test(S(A(3)), 0, 0);
test(S(A(3)), 0, 1);
test(S(A(3)), 1, 0);
test(S(A(3)), 1, 1);
test(S(A(3)), 1, 2);
test(S("1", A(5)), 0, 0);
test(S("1", A(5)), 0, 1);
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 50, 0);
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 50, 1);
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 50, 10);
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 50, 100);
test(S(A(3)), 0, 0, A(4));
test(S(A(3)), 0, 1, A(4));
test(S(A(3)), 1, 0, A(4));
test(S(A(3)), 1, 1, A(4));
test(S(A(3)), 1, 2, A(4));
test(S("1", A(5)), 0, 0, A(6));
test(S("1", A(5)), 0, 1, A(6));
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 50, 0, A(8));
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 50, 1, A(8));
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 50, 10, A(8));
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 50, 100, A(8));
}
#if TEST_STD_VER >= 11
{
typedef min_allocator<char> A;
typedef std::basic_string<char, std::char_traits<char>, A> S;
test(S(A()), 0);
test(S(A()), 1);
test(S("1", A()), 0);
test(S("1", A()), 1);
test(S("1", A()), 2);
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 0);
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 5);
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 50);
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 500);
test(S(A()), 0, 0);
test(S(A()), 0, 1);
test(S(A()), 1, 0);
test(S(A()), 1, 1);
test(S(A()), 1, 2);
test(S("1", A()), 0, 0);
test(S("1", A()), 0, 1);
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 50, 0);
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 50, 1);
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 50, 10);
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 50, 100);
test(S(A()), 0, 0, A());
test(S(A()), 0, 1, A());
test(S(A()), 1, 0, A());
test(S(A()), 1, 1, A());
test(S(A()), 1, 2, A());
test(S("1", A()), 0, 0, A());
test(S("1", A()), 0, 1, A());
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 50, 0, A());
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 50, 1, A());
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 50, 10, A());
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 50, 100, A());
}
#endif
return true;
}
int main(int, char**)
{
test();
#if TEST_STD_VER > 17
static_assert(test());
#endif
test_lwg2583();
return 0;
}