Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,23 @@
#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;
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, "");
static_assert(!std::is_nothrow_move_constructible<C>::value, "");
#else
static_assert( std::is_nothrow_move_constructible<C>::value, "");
static_assert(std::is_nothrow_move_constructible<C>::value, "");
#endif
}
}

return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,38 +21,34 @@
#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());
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 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("");
Expand All @@ -66,9 +62,9 @@ TEST_CONSTEXPR_CXX20 bool test() {

test("123456798012345679801234567980123456798012345679801234567980");
test("123456798012345679801234567980123456798012345679801234567980", A(2));
}
}
#if TEST_STD_VER >= 11
{
{
typedef min_allocator<char> A;

test("");
Expand All @@ -82,14 +78,13 @@ TEST_CONSTEXPR_CXX20 bool test() {

test("123456798012345679801234567980123456798012345679801234567980");
test("123456798012345679801234567980123456798012345679801234567980", A());
}
}
#endif

return true;
}

int main(int, char**)
{
int main(int, char**) {
test();
#if TEST_STD_VER > 17
static_assert(test());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@
#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 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());
}

template <class S>
Expand All @@ -37,15 +35,13 @@ TEST_CONSTEXPR_CXX20 void test_string() {
test(S("1"), "2");
test(S("1"), "2");

test(S(),
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
test(S("123456789"),
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
test(S(), "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
test(S("123456789"), "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
test(S("1234567890123456789012345678901234567890123456789012345678901234567890"),
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
test(S("1234567890123456789012345678901234567890123456789012345678901234567890"
"1234567890123456789012345678901234567890123456789012345678901234567890"),
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
"1234567890123456789012345678901234567890123456789012345678901234567890"),
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
}

TEST_CONSTEXPR_CXX20 bool test() {
Expand All @@ -57,8 +53,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
return true;
}

int main(int, char**)
{
int main(int, char**) {
test();
#if TEST_STD_VER > 17
static_assert(test());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,28 @@
#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());
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 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() {
Expand Down Expand Up @@ -83,7 +79,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
#endif

#if TEST_STD_VER >= 11
{ // LWG 2946
{ // LWG 2946
std::string s({"abc", 1});
assert(s.size() == 1);
assert(s == "a");
Expand All @@ -93,8 +89,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
return true;
}

int main(int, char**)
{
int main(int, char**) {
test();
#if TEST_STD_VER > 17
static_assert(test());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,63 +21,55 @@
#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());
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());
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());
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 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() {
Expand Down Expand Up @@ -123,8 +115,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
return true;
}

int main(int, char**)
{
int main(int, char**) {
test();
#if TEST_STD_VER > 17
static_assert(test());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@ 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;
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());
Expand All @@ -51,11 +49,9 @@ test(std::basic_string_view<charT> sv)
}

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;
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());
Expand Down Expand Up @@ -84,7 +80,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
test(SV(""), A(2));

test(SV("1"));
test(SV("1") ,A(2));
test(SV("1"), A(2));

test(SV("1234567980"));
test(SV("1234567980"), A(2));
Expand All @@ -101,7 +97,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
test(SV(""), A());

test(SV("1"));
test(SV("1") ,A());
test(SV("1"), A());

test(SV("1234567980"));
test(SV("1234567980"), A());
Expand All @@ -114,8 +110,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
return true;
}

int main(int, char**)
{
int main(int, char**) {
test();
#if TEST_STD_VER > 17
static_assert(test());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@
#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 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());
}

template <class S>
Expand All @@ -37,15 +35,13 @@ TEST_CONSTEXPR_CXX20 void test_string() {
test(S("1"), SV("2"));
test(S("1"), SV("2"));

test(S(),
SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
test(S("123456789"),
SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
test(S(), SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
test(S("123456789"), SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
test(S("1234567890123456789012345678901234567890123456789012345678901234567890"),
SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
test(S("1234567890123456789012345678901234567890123456789012345678901234567890"
"1234567890123456789012345678901234567890123456789012345678901234567890"),
SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
"1234567890123456789012345678901234567890123456789012345678901234567890"),
SV("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
}

TEST_CONSTEXPR_CXX20 bool test() {
Expand All @@ -57,8 +53,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
return true;
}

int main(int, char**)
{
int main(int, char**) {
test();
#if TEST_STD_VER > 17
static_assert(test());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,26 @@
#include "min_allocator.h"

template <class StringView, class Allocator, class = void>
struct CanDeduce : std::false_type { };
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 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);
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>>, "");
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);
}
Expand All @@ -59,9 +60,9 @@ TEST_CONSTEXPR_CXX20 bool test() {
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>>, "");
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);
}
Expand All @@ -70,9 +71,9 @@ TEST_CONSTEXPR_CXX20 bool test() {
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>>, "");
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);
}
Expand All @@ -82,9 +83,9 @@ TEST_CONSTEXPR_CXX20 bool test() {
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>>, "");
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);
}
Expand All @@ -93,18 +94,18 @@ TEST_CONSTEXPR_CXX20 bool test() {
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>>, "");
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::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);
Expand All @@ -113,8 +114,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
return true;
}

int main(int, char**)
{
int main(int, char**) {
test();
#if TEST_STD_VER > 17
static_assert(test());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,29 @@
#include "min_allocator.h"

template <class StringView, class Size, class Allocator, class = void>
struct CanDeduce : std::false_type { };
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 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);
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>>, "");
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);
}
Expand All @@ -63,9 +67,9 @@ TEST_CONSTEXPR_CXX20 bool test() {
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>>, "");
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);
}
Expand All @@ -74,9 +78,9 @@ TEST_CONSTEXPR_CXX20 bool test() {
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>>, "");
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);
}
Expand All @@ -86,9 +90,9 @@ TEST_CONSTEXPR_CXX20 bool test() {
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>>, "");
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);
}
Expand All @@ -97,18 +101,18 @@ TEST_CONSTEXPR_CXX20 bool test() {
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>>, "");
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::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);
Expand All @@ -117,8 +121,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
return true;
}

int main(int, char**)
{
int main(int, char**) {
test();
#if TEST_STD_VER > 17
static_assert(test());
Expand Down
162 changes: 71 additions & 91 deletions libcxx/test/std/strings/basic.string/string.cons/substr.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,113 +28,94 @@
#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());
}
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());
}
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());
}
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());
}
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());
}
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());
}
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()
{
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);
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
}

Expand Down Expand Up @@ -221,8 +202,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
return true;
}

int main(int, char**)
{
int main(int, char**) {
test();
#if TEST_STD_VER > 17
static_assert(test());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,25 @@

#include "test_macros.h"

constexpr bool test()
{
using S = std::string;
constexpr bool test() {
using S = std::string;

S s1 {};
S s2 {"abcde", 5};
S s1{};
S s2{"abcde", 5};

ASSERT_NOEXCEPT(s1.contains('e'));
ASSERT_NOEXCEPT(s1.contains('e'));

assert(!s1.contains('c'));
assert(!s1.contains('e'));
assert(!s1.contains('x'));
assert( s2.contains('c'));
assert( s2.contains('e'));
assert(!s2.contains('x'));
assert(!s1.contains('c'));
assert(!s1.contains('e'));
assert(!s1.contains('x'));
assert(s2.contains('c'));
assert(s2.contains('e'));
assert(!s2.contains('x'));

return true;
return true;
}

int main(int, char**)
{
int main(int, char**) {
test();
static_assert(test());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,57 +16,55 @@

#include "test_macros.h"

constexpr bool test()
{
using S = std::string;
constexpr bool test() {
using S = std::string;

const char* s = "abcde";
S s0;
S s1 {s + 4, 1};
S s3 {s + 2, 3};
S sNot {"xyz", 3};
const char* s = "abcde";
S s0;
S s1{s + 4, 1};
S s3{s + 2, 3};
S sNot{"xyz", 3};

assert(s0.contains(""));
assert(!s0.contains("e"));
assert(s0.contains(""));
assert(!s0.contains("e"));

assert( s1.contains(""));
assert(!s1.contains("d"));
assert( s1.contains("e"));
assert(!s1.contains("de"));
assert(!s1.contains("cd"));
assert(!s1.contains("cde"));
assert(!s1.contains("bcde"));
assert(!s1.contains("abcde"));
assert(!s1.contains("xyz"));
assert(s1.contains(""));
assert(!s1.contains("d"));
assert(s1.contains("e"));
assert(!s1.contains("de"));
assert(!s1.contains("cd"));
assert(!s1.contains("cde"));
assert(!s1.contains("bcde"));
assert(!s1.contains("abcde"));
assert(!s1.contains("xyz"));

assert( s3.contains(""));
assert( s3.contains("d"));
assert( s3.contains("e"));
assert( s3.contains("de"));
assert( s3.contains("cd"));
assert(!s3.contains("ce"));
assert( s3.contains("cde"));
assert(!s3.contains("edc"));
assert(!s3.contains("bcde"));
assert(!s3.contains("abcde"));
assert(!s3.contains("xyz"));
assert(s3.contains(""));
assert(s3.contains("d"));
assert(s3.contains("e"));
assert(s3.contains("de"));
assert(s3.contains("cd"));
assert(!s3.contains("ce"));
assert(s3.contains("cde"));
assert(!s3.contains("edc"));
assert(!s3.contains("bcde"));
assert(!s3.contains("abcde"));
assert(!s3.contains("xyz"));

assert( sNot.contains(""));
assert(!sNot.contains("d"));
assert(!sNot.contains("e"));
assert(!sNot.contains("de"));
assert(!sNot.contains("cd"));
assert(!sNot.contains("cde"));
assert(!sNot.contains("bcde"));
assert(!sNot.contains("abcde"));
assert( sNot.contains("xyz"));
assert(!sNot.contains("zyx"));
assert(sNot.contains(""));
assert(!sNot.contains("d"));
assert(!sNot.contains("e"));
assert(!sNot.contains("de"));
assert(!sNot.contains("cd"));
assert(!sNot.contains("cde"));
assert(!sNot.contains("bcde"));
assert(!sNot.contains("abcde"));
assert(sNot.contains("xyz"));
assert(!sNot.contains("zyx"));

return true;
return true;
}

int main(int, char**)
{
int main(int, char**) {
test();
static_assert(test());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,78 +16,76 @@

#include "test_macros.h"

constexpr bool test()
{
using S = std::string;
using SV = std::string_view;

const char* s = "abcde";
S s0;
S s1 {s + 1, 1};
S s3 {s + 1, 3};
S s5 {s , 5};
S sNot {"xyz", 3};

SV sv0;
SV sv1 {s + 1, 1};
SV sv2 {s + 1, 2};
SV sv3 {s + 1, 3};
SV sv4 {s + 1, 4};
SV sv5 {s , 5};
SV svNot {"xyz", 3};
SV svNot2 {"bd" , 2};
SV svNot3 {"dcb", 3};

ASSERT_NOEXCEPT(s0.contains(sv0));

assert( s0.contains(sv0));
assert(!s0.contains(sv1));

assert( s1.contains(sv0));
assert( s1.contains(sv1));
assert(!s1.contains(sv2));
assert(!s1.contains(sv3));
assert(!s1.contains(sv4));
assert(!s1.contains(sv5));
assert(!s1.contains(svNot));
assert(!s1.contains(svNot2));
assert(!s1.contains(svNot3));

assert( s3.contains(sv0));
assert( s3.contains(sv1));
assert( s3.contains(sv2));
assert( s3.contains(sv3));
assert(!s3.contains(sv4));
assert(!s3.contains(sv5));
assert(!s3.contains(svNot));
assert(!s3.contains(svNot2));
assert(!s3.contains(svNot3));

assert( s5.contains(sv0));
assert( s5.contains(sv1));
assert( s5.contains(sv2));
assert( s5.contains(sv3));
assert( s5.contains(sv4));
assert( s5.contains(sv5));
assert(!s5.contains(svNot));
assert(!s5.contains(svNot2));
assert(!s5.contains(svNot3));

assert( sNot.contains(sv0));
assert(!sNot.contains(sv1));
assert(!sNot.contains(sv2));
assert(!sNot.contains(sv3));
assert(!sNot.contains(sv4));
assert(!sNot.contains(sv5));
assert( sNot.contains(svNot));
assert(!sNot.contains(svNot2));
assert(!sNot.contains(svNot3));

return true;
constexpr bool test() {
using S = std::string;
using SV = std::string_view;

const char* s = "abcde";
S s0;
S s1{s + 1, 1};
S s3{s + 1, 3};
S s5{s, 5};
S sNot{"xyz", 3};

SV sv0;
SV sv1{s + 1, 1};
SV sv2{s + 1, 2};
SV sv3{s + 1, 3};
SV sv4{s + 1, 4};
SV sv5{s, 5};
SV svNot{"xyz", 3};
SV svNot2{"bd", 2};
SV svNot3{"dcb", 3};

ASSERT_NOEXCEPT(s0.contains(sv0));

assert(s0.contains(sv0));
assert(!s0.contains(sv1));

assert(s1.contains(sv0));
assert(s1.contains(sv1));
assert(!s1.contains(sv2));
assert(!s1.contains(sv3));
assert(!s1.contains(sv4));
assert(!s1.contains(sv5));
assert(!s1.contains(svNot));
assert(!s1.contains(svNot2));
assert(!s1.contains(svNot3));

assert(s3.contains(sv0));
assert(s3.contains(sv1));
assert(s3.contains(sv2));
assert(s3.contains(sv3));
assert(!s3.contains(sv4));
assert(!s3.contains(sv5));
assert(!s3.contains(svNot));
assert(!s3.contains(svNot2));
assert(!s3.contains(svNot3));

assert(s5.contains(sv0));
assert(s5.contains(sv1));
assert(s5.contains(sv2));
assert(s5.contains(sv3));
assert(s5.contains(sv4));
assert(s5.contains(sv5));
assert(!s5.contains(svNot));
assert(!s5.contains(svNot2));
assert(!s5.contains(svNot3));

assert(sNot.contains(sv0));
assert(!sNot.contains(sv1));
assert(!sNot.contains(sv2));
assert(!sNot.contains(sv3));
assert(!sNot.contains(sv4));
assert(!sNot.contains(sv5));
assert(sNot.contains(svNot));
assert(!sNot.contains(svNot2));
assert(!sNot.contains(svNot3));

return true;
}

int main(int, char**)
{
int main(int, char**) {
test();
static_assert(test());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,21 @@
constexpr bool test() {
{
typedef std::string S;
S s1 {};
S s2 { "abcde", 5 };
S s1{};
S s2{"abcde", 5};

ASSERT_NOEXCEPT(s1.ends_with('e'));

assert (!s1.ends_with('e'));
assert (!s1.ends_with('x'));
assert ( s2.ends_with('e'));
assert (!s2.ends_with('x'));
assert(!s1.ends_with('e'));
assert(!s1.ends_with('x'));
assert(s2.ends_with('e'));
assert(!s2.ends_with('x'));
}

return true;
}

int main(int, char**)
{
int main(int, char**) {
test();
static_assert(test());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,44 +19,44 @@
constexpr bool test() {
{
typedef std::string S;
const char *s = "abcde";
const char* s = "abcde";

S s0;
S s1 { s + 4, 1 };
S s2 { s + 3, 2 };
// S s3 { s + 2, 3 };
// S s4 { s + 1, 4 };
// S s5 { s, 5 };
S sNot { "def", 3 };
S s0;
S s1{s + 4, 1};
S s2{s + 3, 2};
// S s3 { s + 2, 3 };
// S s4 { s + 1, 4 };
// S s5 { s, 5 };
S sNot{"def", 3};

LIBCPP_ASSERT_NOEXCEPT(s0.ends_with(""));

assert ( s0.ends_with(""));
assert (!s0.ends_with("e"));
assert(s0.ends_with(""));
assert(!s0.ends_with("e"));

assert ( s1.ends_with(""));
assert ( s1.ends_with("e"));
assert (!s1.ends_with("de"));
assert (!s1.ends_with("cde"));
assert (!s1.ends_with("bcde"));
assert (!s1.ends_with("abcde"));
assert (!s1.ends_with("def"));
assert(s1.ends_with(""));
assert(s1.ends_with("e"));
assert(!s1.ends_with("de"));
assert(!s1.ends_with("cde"));
assert(!s1.ends_with("bcde"));
assert(!s1.ends_with("abcde"));
assert(!s1.ends_with("def"));

assert ( s2.ends_with(""));
assert ( s2.ends_with("e"));
assert ( s2.ends_with("de"));
assert (!s2.ends_with("cde"));
assert (!s2.ends_with("bcde"));
assert (!s2.ends_with("abcde"));
assert (!s2.ends_with("def"));
assert(s2.ends_with(""));
assert(s2.ends_with("e"));
assert(s2.ends_with("de"));
assert(!s2.ends_with("cde"));
assert(!s2.ends_with("bcde"));
assert(!s2.ends_with("abcde"));
assert(!s2.ends_with("def"));

assert ( sNot.ends_with(""));
assert (!sNot.ends_with("e"));
assert (!sNot.ends_with("de"));
assert (!sNot.ends_with("cde"));
assert (!sNot.ends_with("bcde"));
assert (!sNot.ends_with("abcde"));
assert ( sNot.ends_with("def"));
assert(sNot.ends_with(""));
assert(!sNot.ends_with("e"));
assert(!sNot.ends_with("de"));
assert(!sNot.ends_with("cde"));
assert(!sNot.ends_with("bcde"));
assert(!sNot.ends_with("abcde"));
assert(sNot.ends_with("def"));
}

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,52 +20,52 @@ constexpr bool test() {
{
typedef std::string S;
typedef std::string_view SV;
const char *s = "abcde";
const char* s = "abcde";

S s0;
S s1 { s + 4, 1 };
S s2 { s + 3, 2 };
// S s3 { s + 2, 3 };
// S s4 { s + 1, 4 };
// S s5 { s, 5 };
S sNot { "def", 3 };
S s0;
S s1{s + 4, 1};
S s2{s + 3, 2};
// S s3 { s + 2, 3 };
// S s4 { s + 1, 4 };
// S s5 { s, 5 };
S sNot{"def", 3};

SV sv0;
SV sv1 { s + 4, 1 };
SV sv2 { s + 3, 2 };
SV sv3 { s + 2, 3 };
SV sv4 { s + 1, 4 };
SV sv5 { s , 5 };
SV svNot {"def", 3 };
SV sv0;
SV sv1{s + 4, 1};
SV sv2{s + 3, 2};
SV sv3{s + 2, 3};
SV sv4{s + 1, 4};
SV sv5{s, 5};
SV svNot{"def", 3};

ASSERT_NOEXCEPT(s0.ends_with(sv0));

assert ( s0.ends_with(sv0));
assert (!s0.ends_with(sv1));
assert(s0.ends_with(sv0));
assert(!s0.ends_with(sv1));

assert ( s1.ends_with(sv0));
assert ( s1.ends_with(sv1));
assert (!s1.ends_with(sv2));
assert (!s1.ends_with(sv3));
assert (!s1.ends_with(sv4));
assert (!s1.ends_with(sv5));
assert (!s1.ends_with(svNot));
assert(s1.ends_with(sv0));
assert(s1.ends_with(sv1));
assert(!s1.ends_with(sv2));
assert(!s1.ends_with(sv3));
assert(!s1.ends_with(sv4));
assert(!s1.ends_with(sv5));
assert(!s1.ends_with(svNot));

assert ( s2.ends_with(sv0));
assert ( s2.ends_with(sv1));
assert ( s2.ends_with(sv2));
assert (!s2.ends_with(sv3));
assert (!s2.ends_with(sv4));
assert (!s2.ends_with(sv5));
assert (!s2.ends_with(svNot));
assert(s2.ends_with(sv0));
assert(s2.ends_with(sv1));
assert(s2.ends_with(sv2));
assert(!s2.ends_with(sv3));
assert(!s2.ends_with(sv4));
assert(!s2.ends_with(sv5));
assert(!s2.ends_with(svNot));

assert ( sNot.ends_with(sv0));
assert (!sNot.ends_with(sv1));
assert (!sNot.ends_with(sv2));
assert (!sNot.ends_with(sv3));
assert (!sNot.ends_with(sv4));
assert (!sNot.ends_with(sv5));
assert ( sNot.ends_with(svNot));
assert(sNot.ends_with(sv0));
assert(!sNot.ends_with(sv1));
assert(!sNot.ends_with(sv2));
assert(!sNot.ends_with(sv3));
assert(!sNot.ends_with(sv4));
assert(!sNot.ends_with(sv5));
assert(sNot.ends_with(svNot));
}

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,14 @@
#include "min_allocator.h"

template <class S>
TEST_CONSTEXPR_CXX20 void
test(S s)
{
const S& cs = s;
typename S::iterator b = s.begin();
typename S::const_iterator cb = cs.begin();
if (!s.empty())
{
assert(*b == s[0]);
}
assert(b == cb);
TEST_CONSTEXPR_CXX20 void test(S s) {
const S& cs = s;
typename S::iterator b = s.begin();
typename S::const_iterator cb = cs.begin();
if (!s.empty()) {
assert(*b == s[0]);
}
assert(b == cb);
}

TEST_CONSTEXPR_CXX20 bool test() {
Expand All @@ -48,8 +45,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
return true;
}

int main(int, char**)
{
int main(int, char**) {
test();
#if TEST_STD_VER > 17
static_assert(test());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@
#include "min_allocator.h"

template <class S>
TEST_CONSTEXPR_CXX20 void
test(const S& s)
{
typename S::const_iterator cb = s.cbegin();
if (!s.empty())
{
assert(*cb == s[0]);
}
assert(cb == s.begin());
TEST_CONSTEXPR_CXX20 void test(const S& s) {
typename S::const_iterator cb = s.cbegin();
if (!s.empty()) {
assert(*cb == s[0]);
}
assert(cb == s.begin());
}

TEST_CONSTEXPR_CXX20 bool test() {
Expand All @@ -45,8 +42,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
return true;
}

int main(int, char**)
{
int main(int, char**) {
test();
#if TEST_STD_VER > 17
static_assert(test());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@
#include "min_allocator.h"

template <class S>
TEST_CONSTEXPR_CXX20 void
test(const S& s)
{
typename S::const_iterator ce = s.cend();
assert(ce == s.end());
TEST_CONSTEXPR_CXX20 void test(const S& s) {
typename S::const_iterator ce = s.cend();
assert(ce == s.end());
}

TEST_CONSTEXPR_CXX20 bool test() {
Expand All @@ -41,8 +39,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
return true;
}

int main(int, char**)
{
int main(int, char**) {
test();
#if TEST_STD_VER > 17
static_assert(test());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@
#include "min_allocator.h"

template <class S>
TEST_CONSTEXPR_CXX20 void
test(const S& s)
{
typename S::const_reverse_iterator cb = s.crbegin();
if (!s.empty())
{
assert(*cb == s.back());
}
assert(cb == s.rbegin());
TEST_CONSTEXPR_CXX20 void test(const S& s) {
typename S::const_reverse_iterator cb = s.crbegin();
if (!s.empty()) {
assert(*cb == s.back());
}
assert(cb == s.rbegin());
}

TEST_CONSTEXPR_CXX20 bool test() {
Expand All @@ -45,8 +42,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
return true;
}

int main(int, char**)
{
int main(int, char**) {
test();
#if TEST_STD_VER > 17
static_assert(test());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@
#include "min_allocator.h"

template <class S>
TEST_CONSTEXPR_CXX20 void
test(const S& s)
{
typename S::const_reverse_iterator ce = s.crend();
assert(ce == s.rend());
TEST_CONSTEXPR_CXX20 void test(const S& s) {
typename S::const_reverse_iterator ce = s.crend();
assert(ce == s.rend());
}

TEST_CONSTEXPR_CXX20 bool test() {
Expand All @@ -41,8 +39,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
return true;
}

int main(int, char**)
{
int main(int, char**) {
test();
#if TEST_STD_VER > 17
static_assert(test());
Expand Down
26 changes: 11 additions & 15 deletions libcxx/test/std/strings/basic.string/string.iterators/end.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,16 @@
#include "min_allocator.h"

template <class S>
TEST_CONSTEXPR_CXX20 void
test(S s)
{
const S& cs = s;
typename S::iterator e = s.end();
typename S::const_iterator ce = cs.end();
if (s.empty())
{
assert(e == s.begin());
assert(ce == cs.begin());
}
assert(static_cast<std::size_t>(e - s.begin()) == s.size());
assert(static_cast<std::size_t>(ce - cs.begin()) == cs.size());
TEST_CONSTEXPR_CXX20 void test(S s) {
const S& cs = s;
typename S::iterator e = s.end();
typename S::const_iterator ce = cs.end();
if (s.empty()) {
assert(e == s.begin());
assert(ce == cs.begin());
}
assert(static_cast<std::size_t>(e - s.begin()) == s.size());
assert(static_cast<std::size_t>(ce - cs.begin()) == cs.size());
}

TEST_CONSTEXPR_CXX20 bool test() {
Expand All @@ -51,8 +48,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
return true;
}

int main(int, char**)
{
int main(int, char**) {
test();
#if TEST_STD_VER > 17
static_assert(test());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@

#include <iterator>

using iterator = std::string::iterator;
using const_iterator = std::string::const_iterator;
using reverse_iterator = std::string::reverse_iterator;
using iterator = std::string::iterator;
using const_iterator = std::string::const_iterator;
using reverse_iterator = std::string::reverse_iterator;
using const_reverse_iterator = std::string::const_reverse_iterator;
using value_type = char;
using value_type = char;

static_assert(std::contiguous_iterator<iterator>);
static_assert(std::indirectly_writable<iterator, value_type>);
Expand All @@ -30,23 +30,23 @@ static_assert(std::sized_sentinel_for<iterator, iterator>);
static_assert(std::sized_sentinel_for<iterator, const_iterator>);
static_assert(!std::sized_sentinel_for<iterator, reverse_iterator>);
static_assert(!std::sized_sentinel_for<iterator, const_reverse_iterator>);
static_assert( std::indirectly_movable<iterator, iterator>);
static_assert( std::indirectly_movable_storable<iterator, iterator>);
static_assert(std::indirectly_movable<iterator, iterator>);
static_assert(std::indirectly_movable_storable<iterator, iterator>);
static_assert(!std::indirectly_movable<iterator, const_iterator>);
static_assert(!std::indirectly_movable_storable<iterator, const_iterator>);
static_assert( std::indirectly_movable<iterator, reverse_iterator>);
static_assert( std::indirectly_movable_storable<iterator, reverse_iterator>);
static_assert(std::indirectly_movable<iterator, reverse_iterator>);
static_assert(std::indirectly_movable_storable<iterator, reverse_iterator>);
static_assert(!std::indirectly_movable<iterator, const_reverse_iterator>);
static_assert(!std::indirectly_movable_storable<iterator, const_reverse_iterator>);
static_assert( std::indirectly_copyable<iterator, iterator>);
static_assert( std::indirectly_copyable_storable<iterator, iterator>);
static_assert(std::indirectly_copyable<iterator, iterator>);
static_assert(std::indirectly_copyable_storable<iterator, iterator>);
static_assert(!std::indirectly_copyable<iterator, const_iterator>);
static_assert(!std::indirectly_copyable_storable<iterator, const_iterator>);
static_assert( std::indirectly_copyable<iterator, reverse_iterator>);
static_assert( std::indirectly_copyable_storable<iterator, reverse_iterator>);
static_assert(std::indirectly_copyable<iterator, reverse_iterator>);
static_assert(std::indirectly_copyable_storable<iterator, reverse_iterator>);
static_assert(!std::indirectly_copyable<iterator, const_reverse_iterator>);
static_assert(!std::indirectly_copyable_storable<iterator, const_reverse_iterator>);
static_assert( std::indirectly_swappable<iterator, iterator>);
static_assert(std::indirectly_swappable<iterator, iterator>);

static_assert(std::contiguous_iterator<const_iterator>);
static_assert(!std::indirectly_writable<const_iterator, value_type>);
Expand All @@ -58,20 +58,20 @@ static_assert(std::sized_sentinel_for<const_iterator, iterator>);
static_assert(std::sized_sentinel_for<const_iterator, const_iterator>);
static_assert(!std::sized_sentinel_for<const_iterator, reverse_iterator>);
static_assert(!std::sized_sentinel_for<const_iterator, const_reverse_iterator>);
static_assert( std::indirectly_movable<const_iterator, iterator>);
static_assert( std::indirectly_movable_storable<const_iterator, iterator>);
static_assert(std::indirectly_movable<const_iterator, iterator>);
static_assert(std::indirectly_movable_storable<const_iterator, iterator>);
static_assert(!std::indirectly_movable<const_iterator, const_iterator>);
static_assert(!std::indirectly_movable_storable<const_iterator, const_iterator>);
static_assert( std::indirectly_movable<const_iterator, reverse_iterator>);
static_assert( std::indirectly_movable_storable<const_iterator, reverse_iterator>);
static_assert(std::indirectly_movable<const_iterator, reverse_iterator>);
static_assert(std::indirectly_movable_storable<const_iterator, reverse_iterator>);
static_assert(!std::indirectly_movable<const_iterator, const_reverse_iterator>);
static_assert(!std::indirectly_movable_storable<const_iterator, const_reverse_iterator>);
static_assert( std::indirectly_copyable<const_iterator, iterator>);
static_assert( std::indirectly_copyable_storable<const_iterator, iterator>);
static_assert(std::indirectly_copyable<const_iterator, iterator>);
static_assert(std::indirectly_copyable_storable<const_iterator, iterator>);
static_assert(!std::indirectly_copyable<const_iterator, const_iterator>);
static_assert(!std::indirectly_copyable_storable<const_iterator, const_iterator>);
static_assert( std::indirectly_copyable<const_iterator, reverse_iterator>);
static_assert( std::indirectly_copyable_storable<const_iterator, reverse_iterator>);
static_assert(std::indirectly_copyable<const_iterator, reverse_iterator>);
static_assert(std::indirectly_copyable_storable<const_iterator, reverse_iterator>);
static_assert(!std::indirectly_copyable<const_iterator, const_reverse_iterator>);
static_assert(!std::indirectly_copyable_storable<const_iterator, const_reverse_iterator>);
static_assert(!std::indirectly_swappable<const_iterator, const_iterator>);
Original file line number Diff line number Diff line change
Expand Up @@ -22,64 +22,62 @@

#include "test_macros.h"

template<class C>
TEST_CONSTEXPR_CXX20 void test()
{
{ // N3644 testing
typename C::iterator ii1{}, ii2{};
typename C::iterator ii4 = ii1;
typename C::const_iterator cii{};
template <class C>
TEST_CONSTEXPR_CXX20 void test() {
{ // N3644 testing
typename C::iterator ii1{}, ii2{};
typename C::iterator ii4 = ii1;
typename C::const_iterator cii{};

assert ( ii1 == ii2 );
assert ( ii1 == ii4 );
assert(ii1 == ii2);
assert(ii1 == ii4);

assert (!(ii1 != ii2 ));
assert(!(ii1 != ii2));

assert ( (ii1 == cii ));
assert ( (cii == ii1 ));
assert (!(ii1 != cii ));
assert (!(cii != ii1 ));
assert (!(ii1 < cii ));
assert (!(cii < ii1 ));
assert ( (ii1 <= cii ));
assert ( (cii <= ii1 ));
assert (!(ii1 > cii ));
assert (!(cii > ii1 ));
assert ( (ii1 >= cii ));
assert ( (cii >= ii1 ));
assert (cii - ii1 == 0);
assert (ii1 - cii == 0);
}
{
C a;
typename C::iterator i1 = a.begin();
typename C::iterator i2;
i2 = i1;
assert ( i1 == i2 );
}
assert((ii1 == cii));
assert((cii == ii1));
assert(!(ii1 != cii));
assert(!(cii != ii1));
assert(!(ii1 < cii));
assert(!(cii < ii1));
assert((ii1 <= cii));
assert((cii <= ii1));
assert(!(ii1 > cii));
assert(!(cii > ii1));
assert((ii1 >= cii));
assert((cii >= ii1));
assert(cii - ii1 == 0);
assert(ii1 - cii == 0);
}
{
C a;
typename C::iterator i1 = a.begin();
typename C::iterator i2;
i2 = i1;
assert(i1 == i2);
}
}

TEST_CONSTEXPR_CXX20 bool test() {
test<std::string>();
test<std::string>();
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
test<std::wstring>();
test<std::wstring>();
#endif

#ifndef TEST_HAS_NO_CHAR8_T
test<std::u8string>();
test<std::u8string>();
#endif

test<std::u16string>();
test<std::u32string>();
test<std::u16string>();
test<std::u32string>();

return true;
return true;
}

int main(int, char**)
{
test();
int main(int, char**) {
test();
#if TEST_STD_VER > 17
static_assert(test());
static_assert(test());
#endif
return 0;
return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,14 @@
#include "min_allocator.h"

template <class S>
TEST_CONSTEXPR_CXX20 void
test(S s)
{
const S& cs = s;
typename S::reverse_iterator b = s.rbegin();
typename S::const_reverse_iterator cb = cs.rbegin();
if (!s.empty())
{
assert(*b == s.back());
}
assert(b == cb);
TEST_CONSTEXPR_CXX20 void test(S s) {
const S& cs = s;
typename S::reverse_iterator b = s.rbegin();
typename S::const_reverse_iterator cb = cs.rbegin();
if (!s.empty()) {
assert(*b == s.back());
}
assert(b == cb);
}

TEST_CONSTEXPR_CXX20 bool test() {
Expand All @@ -48,8 +45,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
return true;
}

int main(int, char**)
{
int main(int, char**) {
test();
#if TEST_STD_VER > 17
static_assert(test());
Expand Down
26 changes: 11 additions & 15 deletions libcxx/test/std/strings/basic.string/string.iterators/rend.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,16 @@
#include "min_allocator.h"

template <class S>
TEST_CONSTEXPR_CXX20 void
test(S s)
{
const S& cs = s;
typename S::reverse_iterator e = s.rend();
typename S::const_reverse_iterator ce = cs.rend();
if (s.empty())
{
assert(e == s.rbegin());
assert(ce == cs.rbegin());
}
assert(static_cast<std::size_t>(e - s.rbegin()) == s.size());
assert(static_cast<std::size_t>(ce - cs.rbegin()) == cs.size());
TEST_CONSTEXPR_CXX20 void test(S s) {
const S& cs = s;
typename S::reverse_iterator e = s.rend();
typename S::const_reverse_iterator ce = cs.rend();
if (s.empty()) {
assert(e == s.rbegin());
assert(ce == cs.rbegin());
}
assert(static_cast<std::size_t>(e - s.rbegin()) == s.size());
assert(static_cast<std::size_t>(ce - cs.rbegin()) == cs.size());
}

TEST_CONSTEXPR_CXX20 bool test() {
Expand All @@ -51,8 +48,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
return true;
}

int main(int, char**)
{
int main(int, char**) {
test();
#if TEST_STD_VER > 17
static_assert(test());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,31 @@
#include "test_macros.h"

struct Incomplete;
template<class T> struct Holder { T t; };
template <class T>
struct Holder {
T t;
};

template<class T>
template <class T>
struct Charlike {
char ch_;
TEST_CONSTEXPR Charlike(char ch) : ch_(ch) {}
TEST_CONSTEXPR operator char() const { return ch_; }
char ch_;
TEST_CONSTEXPR Charlike(char ch) : ch_(ch) {}
TEST_CONSTEXPR operator char() const { return ch_; }
};

TEST_CONSTEXPR_CXX20 bool test() {
std::string s;
Charlike<Holder<Incomplete> > a[] = {'m', 'a', 'h', 'i'};
s.append(a, a+4);
s.assign(a, a+4);
s.insert(s.begin(), a, a+4);
s.replace(s.begin(), s.begin()+4, a, a+4);
s.append(a, a + 4);
s.assign(a, a + 4);
s.insert(s.begin(), a, a + 4);
s.replace(s.begin(), s.begin() + 4, a, a + 4);
assert(s == "mahimahi");

return true;
}

int main(int, char**)
{
int main(int, char**) {
test();
#if TEST_STD_VER > 17
static_assert(test());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,54 +20,40 @@
#include "min_allocator.h"

template <class S, class SV>
TEST_CONSTEXPR_CXX20 void
test(S s, SV sv, typename S::size_type pos, typename S::size_type n, S expected)
{
if (pos <= sv.size())
{
s.append(sv, pos, n);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
}
TEST_CONSTEXPR_CXX20 void test(S s, SV sv, typename S::size_type pos, typename S::size_type n, S expected) {
if (pos <= sv.size()) {
s.append(sv, pos, n);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
}
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED)
{
try
{
s.append(sv, pos, n);
assert(false);
}
catch (std::out_of_range&)
{
assert(pos > sv.size());
}
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
s.append(sv, pos, n);
assert(false);
} catch (std::out_of_range&) {
assert(pos > sv.size());
}
}
#endif
}

template <class S, class SV>
TEST_CONSTEXPR_CXX20 void
test_npos(S s, SV sv, typename S::size_type pos, S expected)
{
if (pos <= sv.size())
{
s.append(sv, pos);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
}
TEST_CONSTEXPR_CXX20 void test_npos(S s, SV sv, typename S::size_type pos, S expected) {
if (pos <= sv.size()) {
s.append(sv, pos);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
}
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED)
{
try
{
s.append(sv, pos);
assert(false);
}
catch (std::out_of_range&)
{
assert(pos > sv.size());
}
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
s.append(sv, pos);
assert(false);
} catch (std::out_of_range&) {
assert(pos > sv.size());
}
}
#endif
}

Expand All @@ -93,8 +79,7 @@ TEST_CONSTEXPR_CXX20 void test_string() {

test(S("12345678901234567890"), SV(), 0, 0, S("12345678901234567890"));
test(S("12345678901234567890"), SV("12345"), 1, 3, S("12345678901234567890234"));
test(S("12345678901234567890"), SV("12345678901234567890"), 5, 10,
S("123456789012345678906789012345"));
test(S("12345678901234567890"), SV("12345678901234567890"), 5, 10, S("123456789012345678906789012345"));
}

TEST_CONSTEXPR_CXX20 bool test() {
Expand All @@ -118,39 +103,39 @@ TEST_CONSTEXPR_CXX20 bool test() {
{
std::string s;
std::string_view sv = "EFGH";
char arr[] = "IJKL";
char arr[] = "IJKL";

s.append("CDEF", 0); // calls append(const char *, len)
s.append("CDEF", 0); // calls append(const char *, len)
assert(s == "");
s.clear();

s.append("QRST", 0, std::string::npos); // calls append(string("QRST"), pos, npos)
assert(s == "QRST");
s.clear();

s.append(sv, 0); // calls append(T, pos, npos)
s.append(sv, 0); // calls append(T, pos, npos)
assert(s == sv);
s.clear();

s.append(sv, 0, std::string::npos); // calls append(T, pos, npos)
s.append(sv, 0, std::string::npos); // calls append(T, pos, npos)
assert(s == sv);
s.clear();

s.append(arr, 0); // calls append(const char *, len)
s.append(arr, 0); // calls append(const char *, len)
assert(s == "");
s.clear();

s.append(arr, 0, std::string::npos); // calls append(string("IJKL"), pos, npos)
s.append(arr, 0, std::string::npos); // calls append(string("IJKL"), pos, npos)
assert(s == "IJKL");
s.clear();

s.append(arr, 0); // calls append(const char *, len)
s.append(arr, 0); // calls append(const char *, len)
assert(s == "");
s.clear();
}

{
std::string s = "ABCD";
std::string s = "ABCD";
std::string_view sv = s;
s.append(sv);
assert(s == "ABCDABCD");
Expand All @@ -165,20 +150,20 @@ TEST_CONSTEXPR_CXX20 bool test() {
}

{
std::string s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
std::string s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
std::string_view sv = s;
s.append(sv);
assert(s == "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ");

sv = s;
s.append(sv, 0, std::string::npos);
assert(s == "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ");
assert(s ==
"ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ");
}
return true;
}

int main(int, char**)
{
int main(int, char**) {
test();
#if TEST_STD_VER > 17
static_assert(test());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ int main(int, char**) {

{ // Check that `append_range` returns a reference to the string.
std::string c;
static_assert(std::is_lvalue_reference_v<decltype(
c.append_range(FullContainer_Begin_EmptyRange<char>.input)
)>);
static_assert(std::is_lvalue_reference_v<decltype(c.append_range(FullContainer_Begin_EmptyRange<char>.input))>);
assert(&c.append_range(FullContainer_Begin_EmptyRange<char>.input) == &c);
assert(&c.append_range(FullContainer_Begin_OneElementRange<char>.input) == &c);
assert(&c.append_range(FullContainer_Begin_MidRange<char>.input) == &c);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,96 +19,125 @@
#include "min_allocator.h"

template <class S, class It>
TEST_CONSTEXPR_CXX20 void
test(S s, It first, It last, S expected)
{
s.append(first, last);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
TEST_CONSTEXPR_CXX20 void test(S s, It first, It last, S expected) {
s.append(first, last);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
}

#ifndef TEST_HAS_NO_EXCEPTIONS
struct Widget { operator char() const { throw 42; } };
struct Widget {
operator char() const { throw 42; }
};

template <class S, class It>
TEST_CONSTEXPR_CXX20 void
test_exceptions(S s, It first, It last)
{
S original = s;
typename S::iterator begin = s.begin();
typename S::iterator end = s.end();

try {
s.append(first, last);
assert(false);
} catch (...) {}

// Part of "no effects" is that iterators and pointers
// into the string must not have been invalidated.
LIBCPP_ASSERT(s.__invariants());
assert(s == original);
assert(s.begin() == begin);
assert(s.end() == end);
TEST_CONSTEXPR_CXX20 void test_exceptions(S s, It first, It last) {
S original = s;
typename S::iterator begin = s.begin();
typename S::iterator end = s.end();

try {
s.append(first, last);
assert(false);
} catch (...) {
}

// Part of "no effects" is that iterators and pointers
// into the string must not have been invalidated.
LIBCPP_ASSERT(s.__invariants());
assert(s == original);
assert(s.begin() == begin);
assert(s.end() == end);
}
#endif

template <class S>
TEST_CONSTEXPR_CXX20 void test_string() {
const char* s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
test(S(), s, s, S());
test(S(), s, s+1, S("A"));
test(S(), s, s+10, S("ABCDEFGHIJ"));
test(S(), s, s+52, S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
test(S(), s, s + 1, S("A"));
test(S(), s, s + 10, S("ABCDEFGHIJ"));
test(S(), s, s + 52, S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));

test(S("12345"), s, s, S("12345"));
test(S("12345"), s, s+1, S("12345A"));
test(S("12345"), s, s+10, S("12345ABCDEFGHIJ"));
test(S("12345"), s, s+52, S("12345ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
test(S("12345"), s, s + 1, S("12345A"));
test(S("12345"), s, s + 10, S("12345ABCDEFGHIJ"));
test(S("12345"), s, s + 52, S("12345ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));

test(S("1234567890"), s, s, S("1234567890"));
test(S("1234567890"), s, s+1, S("1234567890A"));
test(S("1234567890"), s, s+10, S("1234567890ABCDEFGHIJ"));
test(S("1234567890"), s, s+52, S("1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
test(S("1234567890"), s, s + 1, S("1234567890A"));
test(S("1234567890"), s, s + 10, S("1234567890ABCDEFGHIJ"));
test(S("1234567890"), s, s + 52, S("1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));

test(S("12345678901234567890"), s, s, S("12345678901234567890"));
test(S("12345678901234567890"), s, s+1, S("12345678901234567890""A"));
test(S("12345678901234567890"), s, s+10, S("12345678901234567890""ABCDEFGHIJ"));
test(S("12345678901234567890"), s, s+52,
S("12345678901234567890""ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
test(S("12345678901234567890"),
s,
s + 1,
S("12345678901234567890"
"A"));
test(S("12345678901234567890"),
s,
s + 10,
S("12345678901234567890"
"ABCDEFGHIJ"));
test(S("12345678901234567890"),
s,
s + 52,
S("12345678901234567890"
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));

test(S(), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s), S());
test(S(), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1), S("A"));
test(S(), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10),
S("ABCDEFGHIJ"));
test(S(), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+52),
S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));

test(S("12345"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s),
S("12345"));
test(S("12345"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1),
S("12345A"));
test(S("12345"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10),
S("12345ABCDEFGHIJ"));
test(S("12345"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+52),
S("12345ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));

test(S("1234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s),
S("1234567890"));
test(S("1234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1),
S("1234567890A"));
test(S("1234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10),
S("1234567890ABCDEFGHIJ"));
test(S("1234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+52),
S("1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));

test(S("12345678901234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s),
S("12345678901234567890"));
test(S("12345678901234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+1),
S("12345678901234567890""A"));
test(S("12345678901234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+10),
S("12345678901234567890""ABCDEFGHIJ"));
test(S("12345678901234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s+52),
S("12345678901234567890""ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
test(S(), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s + 1), S("A"));
test(S(), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s + 10), S("ABCDEFGHIJ"));
test(S(),
cpp17_input_iterator<const char*>(s),
cpp17_input_iterator<const char*>(s + 52),
S("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));

test(S("12345"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s), S("12345"));
test(S("12345"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s + 1), S("12345A"));
test(S("12345"),
cpp17_input_iterator<const char*>(s),
cpp17_input_iterator<const char*>(s + 10),
S("12345ABCDEFGHIJ"));
test(S("12345"),
cpp17_input_iterator<const char*>(s),
cpp17_input_iterator<const char*>(s + 52),
S("12345ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));

test(S("1234567890"), cpp17_input_iterator<const char*>(s), cpp17_input_iterator<const char*>(s), S("1234567890"));
test(S("1234567890"),
cpp17_input_iterator<const char*>(s),
cpp17_input_iterator<const char*>(s + 1),
S("1234567890A"));
test(S("1234567890"),
cpp17_input_iterator<const char*>(s),
cpp17_input_iterator<const char*>(s + 10),
S("1234567890ABCDEFGHIJ"));
test(S("1234567890"),
cpp17_input_iterator<const char*>(s),
cpp17_input_iterator<const char*>(s + 52),
S("1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));

test(S("12345678901234567890"),
cpp17_input_iterator<const char*>(s),
cpp17_input_iterator<const char*>(s),
S("12345678901234567890"));
test(S("12345678901234567890"),
cpp17_input_iterator<const char*>(s),
cpp17_input_iterator<const char*>(s + 1),
S("12345678901234567890"
"A"));
test(S("12345678901234567890"),
cpp17_input_iterator<const char*>(s),
cpp17_input_iterator<const char*>(s + 10),
S("12345678901234567890"
"ABCDEFGHIJ"));
test(S("12345678901234567890"),
cpp17_input_iterator<const char*>(s),
cpp17_input_iterator<const char*>(s + 52),
S("12345678901234567890"
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
}

TEST_CONSTEXPR_CXX20 bool test() {
Expand All @@ -123,16 +152,16 @@ TEST_CONSTEXPR_CXX20 bool test() {
typedef ThrowingIterator<char> TIter;
typedef cpp17_input_iterator<TIter> IIter;
const char* s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
test_exceptions(S(), IIter(TIter(s, s+10, 4, TIter::TAIncrement)), IIter(TIter()));
test_exceptions(S(), IIter(TIter(s, s+10, 5, TIter::TADereference)), IIter(TIter()));
test_exceptions(S(), IIter(TIter(s, s+10, 6, TIter::TAComparison)), IIter(TIter()));
test_exceptions(S(), IIter(TIter(s, s + 10, 4, TIter::TAIncrement)), IIter(TIter()));
test_exceptions(S(), IIter(TIter(s, s + 10, 5, TIter::TADereference)), IIter(TIter()));
test_exceptions(S(), IIter(TIter(s, s + 10, 6, TIter::TAComparison)), IIter(TIter()));

test_exceptions(S(), TIter(s, s+10, 4, TIter::TAIncrement), TIter());
test_exceptions(S(), TIter(s, s+10, 5, TIter::TADereference), TIter());
test_exceptions(S(), TIter(s, s+10, 6, TIter::TAComparison), TIter());
test_exceptions(S(), TIter(s, s + 10, 4, TIter::TAIncrement), TIter());
test_exceptions(S(), TIter(s, s + 10, 5, TIter::TADereference), TIter());
test_exceptions(S(), TIter(s, s + 10, 6, TIter::TAComparison), TIter());

Widget w[100];
test_exceptions(S(), w, w+100);
test_exceptions(S(), w, w + 100);
}
#endif

Expand Down Expand Up @@ -162,23 +191,24 @@ TEST_CONSTEXPR_CXX20 bool test() {
}

{ // regression-test appending to self in sneaky ways
std::string s_short = "hello";
std::string s_long = "Lorem ipsum dolor sit amet, consectetur/";
std::string s_short = "hello";
std::string s_long = "Lorem ipsum dolor sit amet, consectetur/";
std::string s_othertype = "hello";
std::string s_sneaky = "hello";
std::string s_sneaky = "hello";

test(s_short, s_short.data() + s_short.size(), s_short.data() + s_short.size() + 1,
std::string("hello\0", 6));
test(s_long, s_long.data() + s_long.size(), s_long.data() + s_long.size() + 1,
test(s_short, s_short.data() + s_short.size(), s_short.data() + s_short.size() + 1, std::string("hello\0", 6));
test(s_long,
s_long.data() + s_long.size(),
s_long.data() + s_long.size() + 1,
std::string("Lorem ipsum dolor sit amet, consectetur/\0", 41));

s_sneaky.reserve(12);
test(s_sneaky, s_sneaky.data(), s_sneaky.data() + 6, std::string("hellohello\0", 11));

if (!TEST_IS_CONSTANT_EVALUATED) {
const unsigned char *first = reinterpret_cast<const unsigned char*>(s_othertype.data());
test(s_othertype, first + 2, first + 5, std::string("hellollo"));
}
if (!TEST_IS_CONSTANT_EVALUATED) {
const unsigned char* first = reinterpret_cast<const unsigned char*>(s_othertype.data());
test(s_othertype, first + 2, first + 5, std::string("hellollo"));
}
}

{ // test with a move iterator that returns char&&
Expand All @@ -201,8 +231,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
return true;
}

int main(int, char**)
{
int main(int, char**) {
test();
#if TEST_STD_VER > 17
static_assert(test());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@
#include "min_allocator.h"

template <class S>
TEST_CONSTEXPR_CXX20 void
test(S s, const typename S::value_type* str, S expected)
{
s.append(str);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
TEST_CONSTEXPR_CXX20 void test(S s, const typename S::value_type* str, S expected) {
s.append(str);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
}

template <class S>
Expand All @@ -38,8 +36,7 @@ TEST_CONSTEXPR_CXX20 void test_string() {

test(S("12345678901234567890"), "", S("12345678901234567890"));
test(S("12345678901234567890"), "12345", S("1234567890123456789012345"));
test(S("12345678901234567890"), "12345678901234567890",
S("1234567890123456789012345678901234567890"));
test(S("12345678901234567890"), "12345678901234567890", S("1234567890123456789012345678901234567890"));
}

TEST_CONSTEXPR_CXX20 bool test() {
Expand All @@ -66,8 +63,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
return true;
}

int main(int, char**)
{
int main(int, char**) {
test();
#if TEST_STD_VER > 17
static_assert(test());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@
#include "min_allocator.h"

template <class S>
TEST_CONSTEXPR_CXX20 void
test(S s, const typename S::value_type* str, typename S::size_type n, S expected)
{
s.append(str, n);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
TEST_CONSTEXPR_CXX20 void test(S s, const typename S::value_type* str, typename S::size_type n, S expected) {
s.append(str, n);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
}

template <class S>
Expand All @@ -43,8 +41,7 @@ TEST_CONSTEXPR_CXX20 void test_string() {

test(S("12345678901234567890"), "", 0, S("12345678901234567890"));
test(S("12345678901234567890"), "12345", 5, S("1234567890123456789012345"));
test(S("12345678901234567890"), "12345678901234567890", 20,
S("1234567890123456789012345678901234567890"));
test(S("12345678901234567890"), "12345678901234567890", 20, S("1234567890123456789012345678901234567890"));
}

TEST_CONSTEXPR_CXX20 bool test() {
Expand Down Expand Up @@ -72,8 +69,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
return true;
}

int main(int, char**)
{
int main(int, char**) {
test();
#if TEST_STD_VER > 17
static_assert(test());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,46 +23,44 @@ struct VeryLarge {
};

namespace std {
template <>
struct char_traits<VeryLarge> {
using char_type = VeryLarge;
using int_type = int;
using off_type = streamoff;
using pos_type = streampos;
using state_type = mbstate_t;
template <>
struct char_traits<VeryLarge> {
using char_type = VeryLarge;
using int_type = int;
using off_type = streamoff;
using pos_type = streampos;
using state_type = mbstate_t;

static TEST_CONSTEXPR_CXX20 void assign(char_type& c1, const char_type& c2) { c1 = c2; }
static bool eq(char_type c1, char_type c2);
static bool lt(char_type c1, char_type c2);
static TEST_CONSTEXPR_CXX20 void assign(char_type& c1, const char_type& c2) { c1 = c2; }
static bool eq(char_type c1, char_type c2);
static bool lt(char_type c1, char_type c2);

static int compare(const char_type* s1, const char_type* s2, std::size_t n);
static std::size_t length(const char_type* s);
static const char_type* find(const char_type* s, std::size_t n, const char_type& a);
static char_type* move(char_type* s1, const char_type* s2, std::size_t n);
static TEST_CONSTEXPR_CXX20 char_type* copy(char_type* s1, const char_type* s2, std::size_t n) {
std::copy_n(s2, n, s1);
return s1;
}
static TEST_CONSTEXPR_CXX20 char_type* assign(char_type* s, std::size_t n, char_type a) {
std::fill_n(s, n, a);
return s;
}
static int compare(const char_type* s1, const char_type* s2, std::size_t n);
static std::size_t length(const char_type* s);
static const char_type* find(const char_type* s, std::size_t n, const char_type& a);
static char_type* move(char_type* s1, const char_type* s2, std::size_t n);
static TEST_CONSTEXPR_CXX20 char_type* copy(char_type* s1, const char_type* s2, std::size_t n) {
std::copy_n(s2, n, s1);
return s1;
}
static TEST_CONSTEXPR_CXX20 char_type* assign(char_type* s, std::size_t n, char_type a) {
std::fill_n(s, n, a);
return s;
}

static int_type not_eof(int_type c);
static char_type to_char_type(int_type c);
static int_type to_int_type(char_type c);
static bool eq_int_type(int_type c1, int_type c2);
static int_type eof();
};
static int_type not_eof(int_type c);
static char_type to_char_type(int_type c);
static int_type to_int_type(char_type c);
static bool eq_int_type(int_type c1, int_type c2);
static int_type eof();
};
} // end namespace std

template <class S>
TEST_CONSTEXPR_CXX20 void
test(S s, typename S::value_type c, S expected)
{
s.push_back(c);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
TEST_CONSTEXPR_CXX20 void test(S s, typename S::value_type c, S expected) {
s.push_back(c);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
}

TEST_CONSTEXPR_CXX20 bool test() {
Expand Down Expand Up @@ -93,8 +91,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
return true;
}

int main(int, char**)
{
int main(int, char**) {
test();
#if TEST_STD_VER > 17
static_assert(test());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@
#include "min_allocator.h"

template <class S>
TEST_CONSTEXPR_CXX20 void
test(S s, typename S::size_type n, typename S::value_type c, S expected)
{
s.append(n, c);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
TEST_CONSTEXPR_CXX20 void test(S s, typename S::size_type n, typename S::value_type c, S expected) {
s.append(n, c);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
}

template <class S>
Expand Down Expand Up @@ -51,8 +49,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
return true;
}

int main(int, char**)
{
int main(int, char**) {
test();
#if TEST_STD_VER > 17
static_assert(test());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@
#include "min_allocator.h"

template <class S>
TEST_CONSTEXPR_CXX20 void
test(S s, S str, S expected)
{
s.append(str);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
TEST_CONSTEXPR_CXX20 void test(S s, S str, S expected) {
s.append(str);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
}

template <class S>
Expand All @@ -46,8 +44,7 @@ TEST_CONSTEXPR_CXX20 void test_string() {
test(S("12345678901234567890"), S(), S("12345678901234567890"));
test(S("12345678901234567890"), S("12345"), S("1234567890123456789012345"));
test(S("12345678901234567890"), S("1234567890"), S("123456789012345678901234567890"));
test(S("12345678901234567890"), S("12345678901234567890"),
S("1234567890123456789012345678901234567890"));
test(S("12345678901234567890"), S("12345678901234567890"), S("1234567890123456789012345678901234567890"));
}

TEST_CONSTEXPR_CXX20 bool test() {
Expand All @@ -57,7 +54,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
#endif

#if TEST_STD_VER >= 11
{ // LWG 2946
{ // LWG 2946
std::string s;
s.append({"abc", 1});
assert(s.size() == 1);
Expand All @@ -68,8 +65,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
return true;
}

int main(int, char**)
{
int main(int, char**) {
test();
#if TEST_STD_VER > 17
static_assert(test());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,54 +20,40 @@
#include "min_allocator.h"

template <class S>
TEST_CONSTEXPR_CXX20 void
test(S s, S str, typename S::size_type pos, typename S::size_type n, S expected)
{
if (pos <= str.size())
{
s.append(str, pos, n);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
}
TEST_CONSTEXPR_CXX20 void test(S s, S str, typename S::size_type pos, typename S::size_type n, S expected) {
if (pos <= str.size()) {
s.append(str, pos, n);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
}
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED)
{
try
{
s.append(str, pos, n);
assert(false);
}
catch (std::out_of_range&)
{
assert(pos > str.size());
}
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
s.append(str, pos, n);
assert(false);
} catch (std::out_of_range&) {
assert(pos > str.size());
}
}
#endif
}

template <class S>
TEST_CONSTEXPR_CXX20 void
test_npos(S s, S str, typename S::size_type pos, S expected)
{
if (pos <= str.size())
{
s.append(str, pos);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
}
TEST_CONSTEXPR_CXX20 void test_npos(S s, S str, typename S::size_type pos, S expected) {
if (pos <= str.size()) {
s.append(str, pos);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
}
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED)
{
try
{
s.append(str, pos);
assert(false);
}
catch (std::out_of_range&)
{
assert(pos > str.size());
}
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
s.append(str, pos);
assert(false);
} catch (std::out_of_range&) {
assert(pos > str.size());
}
}
#endif
}

Expand All @@ -92,8 +78,7 @@ TEST_CONSTEXPR_CXX20 void test_string() {

test(S("12345678901234567890"), S(), 0, 0, S("12345678901234567890"));
test(S("12345678901234567890"), S("12345"), 1, 3, S("12345678901234567890234"));
test(S("12345678901234567890"), S("12345678901234567890"), 5, 10,
S("123456789012345678906789012345"));
test(S("12345678901234567890"), S("12345678901234567890"), 5, 10, S("123456789012345678906789012345"));
}

TEST_CONSTEXPR_CXX20 bool test() {
Expand All @@ -116,8 +101,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
return true;
}

int main(int, char**)
{
int main(int, char**) {
test();
#if TEST_STD_VER > 17
static_assert(test());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@
#include "min_allocator.h"

template <class S, class SV>
TEST_CONSTEXPR_CXX20 void
test(S s, SV sv, S expected)
{
s.append(sv);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
TEST_CONSTEXPR_CXX20 void test(S s, SV sv, S expected) {
s.append(sv);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
}

template <class S>
Expand All @@ -48,8 +46,7 @@ TEST_CONSTEXPR_CXX20 void test_string() {
test(S("12345678901234567890"), SV(), S("12345678901234567890"));
test(S("12345678901234567890"), SV("12345"), S("1234567890123456789012345"));
test(S("12345678901234567890"), SV("1234567890"), S("123456789012345678901234567890"));
test(S("12345678901234567890"), SV("12345678901234567890"),
S("1234567890123456789012345678901234567890"));
test(S("12345678901234567890"), SV("12345678901234567890"), S("1234567890123456789012345678901234567890"));
}

TEST_CONSTEXPR_CXX20 bool test() {
Expand All @@ -61,8 +58,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
return true;
}

int main(int, char**)
{
int main(int, char**) {
test();
#if TEST_STD_VER > 17
static_assert(test());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,54 +19,40 @@
#include "min_allocator.h"

template <class S, class SV>
TEST_CONSTEXPR_CXX20 void
test(S s, SV sv, typename S::size_type pos, typename S::size_type n, S expected)
{
if (pos <= sv.size())
{
s.assign(sv, pos, n);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
}
TEST_CONSTEXPR_CXX20 void test(S s, SV sv, typename S::size_type pos, typename S::size_type n, S expected) {
if (pos <= sv.size()) {
s.assign(sv, pos, n);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
}
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED)
{
try
{
s.assign(sv, pos, n);
assert(false);
}
catch (std::out_of_range&)
{
assert(pos > sv.size());
}
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
s.assign(sv, pos, n);
assert(false);
} catch (std::out_of_range&) {
assert(pos > sv.size());
}
}
#endif
}

template <class S, class SV>
TEST_CONSTEXPR_CXX20 void
test_npos(S s, SV sv, typename S::size_type pos, S expected)
{
if (pos <= sv.size())
{
s.assign(sv, pos);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
}
TEST_CONSTEXPR_CXX20 void test_npos(S s, SV sv, typename S::size_type pos, S expected) {
if (pos <= sv.size()) {
s.assign(sv, pos);
LIBCPP_ASSERT(s.__invariants());
assert(s == expected);
}
#ifndef TEST_HAS_NO_EXCEPTIONS
else if (!TEST_IS_CONSTANT_EVALUATED)
{
try
{
s.assign(sv, pos);
assert(false);
}
catch (std::out_of_range&)
{
assert(pos > sv.size());
}
else if (!TEST_IS_CONSTANT_EVALUATED) {
try {
s.assign(sv, pos);
assert(false);
} catch (std::out_of_range&) {
assert(pos > sv.size());
}
}
#endif
}

Expand All @@ -92,8 +78,7 @@ TEST_CONSTEXPR_CXX20 void test_string() {

test(S("12345678901234567890"), SV(), 0, 0, S());
test(S("12345678901234567890"), SV("12345"), 1, 3, S("234"));
test(S("12345678901234567890"), SV("12345678901234567890"), 5, 10,
S("6789012345"));
test(S("12345678901234567890"), SV("12345678901234567890"), 5, 10, S("6789012345"));
}

TEST_CONSTEXPR_CXX20 bool test() {
Expand All @@ -115,41 +100,41 @@ TEST_CONSTEXPR_CXX20 bool test() {
}

{
std::string s = "ABCD";
std::string s = "ABCD";
std::string_view sv = "EFGH";
char arr[] = "IJKL";
char arr[] = "IJKL";

s.assign("CDEF", 0); // calls assign(const char *, len)
s.assign("CDEF", 0); // calls assign(const char *, len)
assert(s == "");
s.clear();

s.assign("QRST", 0, std::string::npos); // calls assign(string("QRST", pos, len)
assert(s == "QRST");
s.clear();

s.assign(sv, 0); // calls assign(T, pos, npos)
s.assign(sv, 0); // calls assign(T, pos, npos)
assert(s == sv);
s.clear();

s.assign(sv, 0, std::string::npos); // calls assign(T, pos, npos)
s.assign(sv, 0, std::string::npos); // calls assign(T, pos, npos)
assert(s == sv);
s.clear();

s.assign(arr, 0); // calls assign(const char *, len)
s.assign(arr, 0); // calls assign(const char *, len)
assert(s == "");
s.clear();

s.assign(arr, 0, std::string::npos); // calls assign(string("IJKL"), pos, npos)
s.assign(arr, 0, std::string::npos); // calls assign(string("IJKL"), pos, npos)
assert(s == "IJKL");
s.clear();

s.assign(arr, 0); // calls assign(const char *, len)
s.assign(arr, 0); // calls assign(const char *, len)
assert(s == "");
s.clear();
}

{
std::string s = "ABCD";
std::string s = "ABCD";
std::string_view sv = s;
s.assign(sv);
assert(s == "ABCD");
Expand All @@ -160,7 +145,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
}

{
std::string s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
std::string s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
std::string_view sv = s;
s.assign(sv);
assert(s == "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
Expand All @@ -172,8 +157,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
return true;
}

int main(int, char**)
{
int main(int, char**) {
test();
#if TEST_STD_VER > 17
static_assert(test());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ int main(int, char**) {

{ // Check that `assign_range` returns a reference to the string.
std::string c;
static_assert(std::is_lvalue_reference_v<decltype(
c.assign_range(FullContainer_Begin_EmptyRange<char>.input)
)>);
static_assert(std::is_lvalue_reference_v<decltype(c.assign_range(FullContainer_Begin_EmptyRange<char>.input))>);
assert(&c.assign_range(FullContainer_Begin_EmptyRange<char>.input) == &c);
assert(&c.assign_range(FullContainer_Begin_OneElementRange<char>.input) == &c);
assert(&c.assign_range(FullContainer_Begin_MidRange<char>.input) == &c);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
return true;
}

int main(int, char**)
{
int main(int, char**) {
test();
#if TEST_STD_VER > 17
static_assert(test());
Expand Down
Loading