[libc++] Apply clang formatting to all string unit tests
This applies clang-format to the std::string unit tests in preparation for landing https://reviews.llvm.org/D140550. Differential Revision: https://reviews.llvm.org/D140612
This commit is contained in:
committed by
Louis Dionne
parent
823151f0cf
commit
a40bada91a
@@ -25,69 +25,55 @@
|
||||
#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());
|
||||
}
|
||||
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());
|
||||
}
|
||||
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());
|
||||
}
|
||||
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());
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
@@ -95,98 +81,97 @@ 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;
|
||||
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);
|
||||
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));
|
||||
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;
|
||||
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);
|
||||
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());
|
||||
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";
|
||||
S s = "ABCD";
|
||||
SV sv = "EFGH";
|
||||
char arr[] = "IJKL";
|
||||
|
||||
S s1("CDEF", 4); // calls ctor(const char *, len)
|
||||
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)
|
||||
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)
|
||||
S s4(sv, 0, 3); // calls ctor(T, pos, len)
|
||||
assert(s4 == "EFG");
|
||||
|
||||
S s5(arr, 0, 2); // calls ctor(const char *, len)
|
||||
S s5(arr, 0, 2); // calls ctor(const char *, len)
|
||||
assert(s5 == "IJ");
|
||||
|
||||
S s6(arr, 0); // calls ctor(const char *, len)
|
||||
S s6(arr, 0); // calls ctor(const char *, len)
|
||||
assert(s6 == "");
|
||||
|
||||
S s7(s.data(), 2); // calls ctor(const char *, len)
|
||||
S s7(s.data(), 2); // calls ctor(const char *, len)
|
||||
assert(s7 == "AB");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
int main(int, char**) {
|
||||
test();
|
||||
#if TEST_STD_VER > 17
|
||||
static_assert(test());
|
||||
|
||||
@@ -18,14 +18,12 @@
|
||||
#include "min_allocator.h"
|
||||
|
||||
template <class S>
|
||||
TEST_CONSTEXPR_CXX20 void
|
||||
test()
|
||||
{
|
||||
{
|
||||
TEST_CONSTEXPR_CXX20 void test() {
|
||||
{
|
||||
#if TEST_STD_VER > 14
|
||||
static_assert((noexcept(S{})), "" );
|
||||
static_assert((noexcept(S{})), "");
|
||||
#elif TEST_STD_VER >= 11
|
||||
static_assert((noexcept(S()) == noexcept(typename S::allocator_type())), "" );
|
||||
static_assert((noexcept(S()) == noexcept(typename S::allocator_type())), "");
|
||||
#endif
|
||||
S s;
|
||||
LIBCPP_ASSERT(s.__invariants());
|
||||
@@ -33,12 +31,14 @@ test()
|
||||
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{}})), "" );
|
||||
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), "" );
|
||||
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());
|
||||
@@ -46,41 +46,41 @@ test()
|
||||
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
|
||||
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
|
||||
}
|
||||
{
|
||||
# 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
|
||||
@@ -95,8 +95,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());
|
||||
|
||||
@@ -23,20 +23,19 @@ TEST_CONSTEXPR_CXX20 bool test() {
|
||||
// ambiguous.
|
||||
{
|
||||
std::string s = "hello world";
|
||||
s = {};
|
||||
s = {};
|
||||
assert(s.empty());
|
||||
}
|
||||
{
|
||||
std::string s = "hello world";
|
||||
s = {"abc", 2};
|
||||
s = {"abc", 2};
|
||||
assert(s == "ab");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
int main(int, char**) {
|
||||
test();
|
||||
#if TEST_STD_VER > 17
|
||||
static_assert(test());
|
||||
|
||||
@@ -17,15 +17,13 @@
|
||||
#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 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());
|
||||
}
|
||||
|
||||
template <class S>
|
||||
@@ -45,8 +43,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());
|
||||
|
||||
@@ -18,14 +18,12 @@
|
||||
#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 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() {
|
||||
@@ -49,8 +47,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());
|
||||
|
||||
@@ -19,73 +19,70 @@
|
||||
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
struct alloc_imp {
|
||||
bool active;
|
||||
bool active;
|
||||
|
||||
TEST_CONSTEXPR alloc_imp() : active(true) {}
|
||||
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>
|
||||
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>
|
||||
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;
|
||||
typedef T value_type;
|
||||
typedef std::true_type propagate_on_container_copy_assignment;
|
||||
|
||||
alloc_imp *imp;
|
||||
alloc_imp* imp;
|
||||
|
||||
TEST_CONSTEXPR poca_alloc(alloc_imp *imp_) : 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) {}
|
||||
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); }
|
||||
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;
|
||||
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;
|
||||
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);
|
||||
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 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() {
|
||||
@@ -105,12 +102,12 @@ TEST_CONSTEXPR_CXX20 bool test() {
|
||||
test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), A());
|
||||
}
|
||||
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
# 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";
|
||||
const char* p1 = "This is my first string";
|
||||
const char* p2 = "This is my second string";
|
||||
|
||||
alloc_imp imp1;
|
||||
alloc_imp imp2;
|
||||
@@ -125,14 +122,13 @@ TEST_CONSTEXPR_CXX20 bool test() {
|
||||
assert(s1 == p1);
|
||||
assert(s2 == p2);
|
||||
}
|
||||
#endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
int main(int, char**) {
|
||||
test();
|
||||
#if TEST_STD_VER > 17
|
||||
static_assert(test());
|
||||
|
||||
@@ -18,13 +18,11 @@
|
||||
#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 void test(S s1, const S& s2) {
|
||||
s1 = s2;
|
||||
LIBCPP_ASSERT(s1.__invariants());
|
||||
assert(s1 == s2);
|
||||
assert(s1.capacity() >= s1.size());
|
||||
}
|
||||
|
||||
template <class S>
|
||||
@@ -35,15 +33,13 @@ TEST_CONSTEXPR_CXX20 void test_string() {
|
||||
test(S("1"), S("2"));
|
||||
test(S("1"), S("2"));
|
||||
|
||||
test(S(),
|
||||
S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
|
||||
test(S("123456789"),
|
||||
S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
|
||||
test(S(), S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
|
||||
test(S("123456789"), S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
|
||||
test(S("1234567890123456789012345678901234567890123456789012345678901234567890"),
|
||||
S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
|
||||
S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
|
||||
test(S("1234567890123456789012345678901234567890123456789012345678901234567890"
|
||||
"1234567890123456789012345678901234567890123456789012345678901234567890"),
|
||||
S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
|
||||
"1234567890123456789012345678901234567890123456789012345678901234567890"),
|
||||
S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
|
||||
}
|
||||
|
||||
TEST_CONSTEXPR_CXX20 bool test() {
|
||||
@@ -53,7 +49,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
|
||||
#endif
|
||||
|
||||
#if TEST_STD_VER >= 11
|
||||
{ // LWG 2946
|
||||
{ // LWG 2946
|
||||
std::string s;
|
||||
s = {"abc", 1};
|
||||
assert(s.size() == 1);
|
||||
@@ -64,8 +60,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());
|
||||
|
||||
@@ -20,9 +20,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, "");
|
||||
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, "");
|
||||
std::basic_string<char, std::char_traits<char>, limited_allocator<char, 10>>>::value,
|
||||
"");
|
||||
#endif
|
||||
|
||||
TEST_CONSTEXPR_CXX20 bool test() {
|
||||
@@ -32,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());
|
||||
|
||||
@@ -19,12 +19,11 @@
|
||||
#include "test_allocator.h"
|
||||
|
||||
template <class T>
|
||||
struct throwing_alloc
|
||||
{
|
||||
typedef T value_type;
|
||||
throwing_alloc(const throwing_alloc&);
|
||||
T *allocate(std::size_t);
|
||||
~throwing_alloc() noexcept(false);
|
||||
struct throwing_alloc {
|
||||
typedef T value_type;
|
||||
throwing_alloc(const throwing_alloc&);
|
||||
T* allocate(std::size_t);
|
||||
~throwing_alloc() noexcept(false);
|
||||
};
|
||||
|
||||
// Test that it's possible to take the address of basic_string's destructors
|
||||
@@ -35,10 +34,10 @@ std::wstring unused_wide_string;
|
||||
#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, "");
|
||||
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;
|
||||
@@ -53,8 +52,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());
|
||||
|
||||
@@ -21,9 +21,8 @@
|
||||
#include "test_macros.h"
|
||||
|
||||
template <class Container, class Range, class Alloc>
|
||||
concept StringHasFromRangeAllocCtr = requires (Range&& range, const Alloc& alloc) {
|
||||
Container(std::from_range, std::forward<Range>(range), alloc);
|
||||
};
|
||||
concept StringHasFromRangeAllocCtr =
|
||||
requires(Range&& range, const Alloc& alloc) { Container(std::from_range, std::forward<Range>(range), alloc); };
|
||||
|
||||
constexpr bool test_constraints() {
|
||||
// (from_range, range)
|
||||
@@ -42,7 +41,7 @@ constexpr bool test_constraints() {
|
||||
// (from_range, range, alloc)
|
||||
//
|
||||
// Input range with the same value type.
|
||||
using Alloc = test_allocator<char>;
|
||||
using Alloc = test_allocator<char>;
|
||||
using StringWithAlloc = std::basic_string<char, std::char_traits<char>, Alloc>;
|
||||
static_assert(StringHasFromRangeAllocCtr<StringWithAlloc, InputRange<char>, Alloc>);
|
||||
// Input range with a convertible value type.
|
||||
@@ -59,9 +58,7 @@ constexpr bool test_constraints() {
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class Iter,
|
||||
class Sent,
|
||||
class Alloc>
|
||||
template <class Iter, class Sent, class Alloc>
|
||||
constexpr void test_with_input(std::vector<char> input) {
|
||||
auto b = Iter(input.data());
|
||||
auto e = Iter(input.data() + input.size());
|
||||
|
||||
@@ -43,7 +43,9 @@ int main(int, char**) {
|
||||
|
||||
// Note: defining `value_type` is a workaround because one of the deduction guides will end up instantiating
|
||||
// `basic_string`, and that would fail with a hard error if the given allocator doesn't define `value_type`.
|
||||
struct BadAlloc { using value_type = char; };
|
||||
struct BadAlloc {
|
||||
using value_type = char;
|
||||
};
|
||||
SequenceContainerDeductionGuidesSfinaeAway<std::basic_string, std::basic_string<char>, BadAlloc>();
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -46,18 +46,17 @@ using BStr = std::basic_string<T, std::char_traits<T>, Alloc>;
|
||||
// (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
|
||||
{
|
||||
// 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");
|
||||
@@ -70,7 +69,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
|
||||
}
|
||||
{ // Testing (3) w/ allocator
|
||||
std::basic_string s(6ull, 'a', test_allocator<char>{});
|
||||
ASSERT_SAME_TYPE(decltype(s), BStr<char,test_allocator<char>>);
|
||||
ASSERT_SAME_TYPE(decltype(s), BStr<char, test_allocator<char>>);
|
||||
assert(s == "aaaaaa");
|
||||
|
||||
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
|
||||
@@ -86,9 +85,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
|
||||
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>>;
|
||||
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);
|
||||
@@ -102,9 +99,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
|
||||
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>>;
|
||||
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);
|
||||
@@ -118,9 +113,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
|
||||
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>>;
|
||||
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);
|
||||
@@ -134,9 +127,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
|
||||
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>>;
|
||||
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);
|
||||
@@ -160,9 +151,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
|
||||
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>>;
|
||||
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");
|
||||
@@ -185,191 +174,178 @@ TEST_CONSTEXPR_CXX20 bool test() {
|
||||
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>>;
|
||||
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*>;
|
||||
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");
|
||||
}
|
||||
{// (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");
|
||||
}
|
||||
{
|
||||
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");
|
||||
}
|
||||
{ // 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");
|
||||
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");
|
||||
}
|
||||
{ // 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");
|
||||
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");
|
||||
}
|
||||
{ // 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");
|
||||
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");
|
||||
}
|
||||
{ // 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");
|
||||
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");
|
||||
}
|
||||
{ // 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");
|
||||
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");
|
||||
}
|
||||
{ // 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");
|
||||
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");
|
||||
}
|
||||
{ // 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");
|
||||
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");
|
||||
}
|
||||
{ // 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");
|
||||
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");
|
||||
}
|
||||
{ // 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");
|
||||
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");
|
||||
}
|
||||
{ // 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");
|
||||
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**)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
test();
|
||||
#if TEST_STD_VER > 17
|
||||
static_assert(test());
|
||||
|
||||
@@ -48,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());
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
// basic_string(InputIterator begin, InputIterator end,
|
||||
// const Allocator& a = Allocator()); // constexpr since C++20
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <iterator>
|
||||
#include <cassert>
|
||||
@@ -24,42 +23,38 @@
|
||||
#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());
|
||||
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 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() {
|
||||
@@ -70,26 +65,26 @@ TEST_CONSTEXPR_CXX20 bool test() {
|
||||
test(s, s);
|
||||
test(s, s, A(2));
|
||||
|
||||
test(s, s+1);
|
||||
test(s, s+1, 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 + 10);
|
||||
test(s, s + 10, A(2));
|
||||
|
||||
test(s, s+50);
|
||||
test(s, s+50, 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 + 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 + 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));
|
||||
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
|
||||
{
|
||||
@@ -99,43 +94,37 @@ TEST_CONSTEXPR_CXX20 bool test() {
|
||||
test(s, s);
|
||||
test(s, s, A());
|
||||
|
||||
test(s, s+1);
|
||||
test(s, s+1, A());
|
||||
test(s, s + 1);
|
||||
test(s, s + 1, A());
|
||||
|
||||
test(s, s+10);
|
||||
test(s, s+10, A());
|
||||
test(s, s + 10);
|
||||
test(s, s + 10, A());
|
||||
|
||||
test(s, s+50);
|
||||
test(s, s+50, 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 + 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 + 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());
|
||||
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),
|
||||
"");
|
||||
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**)
|
||||
{
|
||||
int main(int, char**) {
|
||||
test();
|
||||
#if TEST_STD_VER > 17
|
||||
static_assert(test());
|
||||
|
||||
@@ -34,74 +34,77 @@ class NotAnIterator {};
|
||||
using NotAnInputIterator = std::back_insert_iterator<std::basic_string<char16_t>>;
|
||||
|
||||
template <typename T>
|
||||
struct NotAnAllocator { typedef T value_type; };
|
||||
struct NotAnAllocator {
|
||||
typedef T value_type;
|
||||
};
|
||||
|
||||
template <class Iter, class Alloc, class = void>
|
||||
struct CanDeduce : std::false_type { };
|
||||
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 { };
|
||||
struct CanDeduce<Iter,
|
||||
Alloc,
|
||||
decltype((void)std::basic_string{std::declval<Iter>(), std::declval<Iter>(), std::declval<Alloc>()})>
|
||||
: std::true_type {};
|
||||
|
||||
static_assert( CanDeduce<char*, std::allocator<char>>::value);
|
||||
static_assert(CanDeduce<char*, std::allocator<char>>::value);
|
||||
static_assert(!CanDeduce<NotAnIterator, std::allocator<char>>::value);
|
||||
static_assert(!CanDeduce<NotAnInputIterator, std::allocator<char16_t>>::value);
|
||||
static_assert(!CanDeduce<char*, NotAnAllocator<char>>::value);
|
||||
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
|
||||
static_assert( CanDeduce<wchar_t*, std::allocator<wchar_t>>::value);
|
||||
static_assert(CanDeduce<wchar_t*, std::allocator<wchar_t>>::value);
|
||||
static_assert(!CanDeduce<wchar_t const*, NotAnAllocator<wchar_t>>::value);
|
||||
#endif
|
||||
|
||||
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>>, "");
|
||||
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>{}};
|
||||
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>>, "");
|
||||
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);
|
||||
}
|
||||
#ifndef TEST_HAS_NO_WIDE_CHARACTERS
|
||||
{
|
||||
const wchar_t* s = L"12345678901234";
|
||||
std::basic_string s1{s, s+10, test_allocator<wchar_t>{}};
|
||||
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>>, "");
|
||||
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);
|
||||
}
|
||||
#endif
|
||||
{
|
||||
const char16_t* s = u"12345678901234";
|
||||
std::basic_string s1{s, s+10, min_allocator<char16_t>{}};
|
||||
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>>, "");
|
||||
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>{}};
|
||||
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::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);
|
||||
@@ -110,8 +113,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());
|
||||
|
||||
@@ -20,16 +20,14 @@
|
||||
#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 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() {
|
||||
@@ -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());
|
||||
|
||||
@@ -20,16 +20,14 @@
|
||||
#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 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() {
|
||||
@@ -38,35 +36,35 @@ TEST_CONSTEXPR_CXX20 bool test() {
|
||||
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{})), "" );
|
||||
static_assert((noexcept(S{})), "");
|
||||
#elif TEST_STD_VER >= 11
|
||||
static_assert((noexcept(S()) == std::is_nothrow_move_constructible<A>::value), "" );
|
||||
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;
|
||||
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{})), "" );
|
||||
static_assert((noexcept(S{})), "");
|
||||
#elif TEST_STD_VER >= 11
|
||||
static_assert((noexcept(S()) == std::is_nothrow_move_constructible<A>::value), "" );
|
||||
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));
|
||||
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 );
|
||||
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{})), "" );
|
||||
static_assert((noexcept(S{})), "");
|
||||
#elif TEST_STD_VER >= 11
|
||||
static_assert((noexcept(S()) == std::is_nothrow_move_constructible<A>::value), "" );
|
||||
static_assert((noexcept(S()) == std::is_nothrow_move_constructible<A>::value), "");
|
||||
#endif
|
||||
test(S(), A());
|
||||
test(S("1"), A());
|
||||
@@ -76,8 +74,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());
|
||||
|
||||
@@ -27,39 +27,36 @@
|
||||
#include "test_allocator.h"
|
||||
|
||||
template <class T>
|
||||
struct some_alloc
|
||||
{
|
||||
typedef T value_type;
|
||||
some_alloc(const some_alloc&);
|
||||
T *allocate(std::size_t);
|
||||
struct some_alloc {
|
||||
typedef T value_type;
|
||||
some_alloc(const some_alloc&);
|
||||
T* allocate(std::size_t);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct some_alloc2
|
||||
{
|
||||
typedef T value_type;
|
||||
struct some_alloc2 {
|
||||
typedef T value_type;
|
||||
|
||||
some_alloc2() {}
|
||||
some_alloc2(const some_alloc2&);
|
||||
T *allocate(std::size_t);
|
||||
void deallocate(void*, unsigned) {}
|
||||
some_alloc2() {}
|
||||
some_alloc2(const some_alloc2&);
|
||||
T* allocate(std::size_t);
|
||||
void deallocate(void*, unsigned) {}
|
||||
|
||||
typedef std::false_type propagate_on_container_move_assignment;
|
||||
typedef std::true_type is_always_equal;
|
||||
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;
|
||||
struct some_alloc3 {
|
||||
typedef T value_type;
|
||||
|
||||
some_alloc3() {}
|
||||
some_alloc3(const some_alloc3&);
|
||||
T *allocate(std::size_t);
|
||||
void deallocate(void*, unsigned) {}
|
||||
some_alloc3() {}
|
||||
some_alloc3(const some_alloc3&);
|
||||
T* allocate(std::size_t);
|
||||
void deallocate(void*, unsigned) {}
|
||||
|
||||
typedef std::false_type propagate_on_container_move_assignment;
|
||||
typedef std::false_type is_always_equal;
|
||||
typedef std::false_type propagate_on_container_move_assignment;
|
||||
typedef std::false_type is_always_equal;
|
||||
};
|
||||
|
||||
TEST_CONSTEXPR_CXX20 bool test() {
|
||||
@@ -75,16 +72,16 @@ TEST_CONSTEXPR_CXX20 bool test() {
|
||||
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, "");
|
||||
static_assert(std::is_nothrow_move_assignable<C>::value, "");
|
||||
#else
|
||||
static_assert(!std::is_nothrow_move_assignable<C>::value, "");
|
||||
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, "");
|
||||
static_assert(std::is_nothrow_move_assignable<C>::value, "");
|
||||
}
|
||||
{
|
||||
// POCMA is false, not always equal
|
||||
@@ -96,8 +93,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());
|
||||
|
||||
@@ -21,15 +21,13 @@
|
||||
#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 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());
|
||||
}
|
||||
|
||||
template <class S>
|
||||
@@ -40,15 +38,13 @@ TEST_CONSTEXPR_CXX20 void test_string() {
|
||||
test(S("1"), S("2"));
|
||||
test(S("1"), S("2"));
|
||||
|
||||
test(S(),
|
||||
S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
|
||||
test(S("123456789"),
|
||||
S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
|
||||
test(S(), S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
|
||||
test(S("123456789"), S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
|
||||
test(S("1234567890123456789012345678901234567890123456789012345678901234567890"),
|
||||
S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
|
||||
S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
|
||||
test(S("1234567890123456789012345678901234567890123456789012345678901234567890"
|
||||
"1234567890123456789012345678901234567890123456789012345678901234567890"),
|
||||
S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
|
||||
"1234567890123456789012345678901234567890123456789012345678901234567890"),
|
||||
S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
|
||||
}
|
||||
|
||||
TEST_CONSTEXPR_CXX20 bool test() {
|
||||
@@ -60,8 +56,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());
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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("");
|
||||
@@ -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("");
|
||||
@@ -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());
|
||||
|
||||
@@ -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>
|
||||
@@ -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() {
|
||||
@@ -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());
|
||||
|
||||
@@ -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() {
|
||||
@@ -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");
|
||||
@@ -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());
|
||||
|
||||
@@ -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() {
|
||||
@@ -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());
|
||||
|
||||
@@ -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());
|
||||
@@ -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());
|
||||
@@ -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));
|
||||
@@ -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());
|
||||
@@ -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());
|
||||
|
||||
@@ -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>
|
||||
@@ -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() {
|
||||
@@ -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());
|
||||
|
||||
@@ -32,15 +32,16 @@
|
||||
#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() {
|
||||
@@ -48,9 +49,9 @@ 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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -93,9 +94,9 @@ 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);
|
||||
}
|
||||
@@ -103,8 +104,8 @@ TEST_CONSTEXPR_CXX20 bool test() {
|
||||
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);
|
||||
@@ -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());
|
||||
|
||||
@@ -36,15 +36,19 @@
|
||||
#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() {
|
||||
@@ -52,9 +56,9 @@ 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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -97,9 +101,9 @@ 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);
|
||||
}
|
||||
@@ -107,8 +111,8 @@ TEST_CONSTEXPR_CXX20 bool test() {
|
||||
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);
|
||||
@@ -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());
|
||||
|
||||
@@ -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;
|
||||
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());
|
||||
}
|
||||
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;
|
||||
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());
|
||||
}
|
||||
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);
|
||||
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);
|
||||
try {
|
||||
vs.emplace_back(s, 5);
|
||||
} catch (const std::out_of_range&) {
|
||||
return;
|
||||
}
|
||||
assert(false);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user