Implement full support for non-pointer pointers in custom allocators for string. This completes the custom pointer support for the entire library.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@185167 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
#include <cassert>
|
||||
|
||||
#include "../test_allocator.h"
|
||||
#include "../min_allocator.h"
|
||||
|
||||
template <class S>
|
||||
void
|
||||
@@ -54,7 +55,7 @@ test(S str, unsigned pos, unsigned n)
|
||||
S s2(str, pos, n);
|
||||
assert(s2.__invariants());
|
||||
assert(pos <= str.size());
|
||||
unsigned rlen = std::min(str.size() - pos, n);
|
||||
unsigned rlen = std::min<unsigned>(str.size() - pos, n);
|
||||
assert(s2.size() == rlen);
|
||||
assert(T::compare(s2.data(), str.data() + pos, rlen) == 0);
|
||||
assert(s2.get_allocator() == A());
|
||||
@@ -77,7 +78,7 @@ test(S str, unsigned pos, unsigned n, const typename S::allocator_type& a)
|
||||
S s2(str, pos, n, a);
|
||||
assert(s2.__invariants());
|
||||
assert(pos <= str.size());
|
||||
unsigned rlen = std::min(str.size() - pos, n);
|
||||
unsigned rlen = std::min<unsigned>(str.size() - pos, n);
|
||||
assert(s2.size() == rlen);
|
||||
assert(T::compare(s2.data(), str.data() + pos, rlen) == 0);
|
||||
assert(s2.get_allocator() == a);
|
||||
@@ -91,6 +92,7 @@ test(S str, unsigned pos, unsigned n, const typename S::allocator_type& a)
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef test_allocator<char> A;
|
||||
typedef std::basic_string<char, std::char_traits<char>, A> S;
|
||||
|
||||
@@ -127,4 +129,45 @@ int main()
|
||||
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 50, 1, A(8));
|
||||
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 50, 10, A(8));
|
||||
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 50, 100, A(8));
|
||||
}
|
||||
#if __cplusplus >= 201103L
|
||||
{
|
||||
typedef min_allocator<char> A;
|
||||
typedef std::basic_string<char, std::char_traits<char>, A> S;
|
||||
|
||||
test(S(A()), 0);
|
||||
test(S(A()), 1);
|
||||
test(S("1", A()), 0);
|
||||
test(S("1", A()), 1);
|
||||
test(S("1", A()), 2);
|
||||
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 0);
|
||||
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 5);
|
||||
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 50);
|
||||
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 500);
|
||||
|
||||
test(S(A()), 0, 0);
|
||||
test(S(A()), 0, 1);
|
||||
test(S(A()), 1, 0);
|
||||
test(S(A()), 1, 1);
|
||||
test(S(A()), 1, 2);
|
||||
test(S("1", A()), 0, 0);
|
||||
test(S("1", A()), 0, 1);
|
||||
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 50, 0);
|
||||
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 50, 1);
|
||||
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 50, 10);
|
||||
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 50, 100);
|
||||
|
||||
test(S(A()), 0, 0, A());
|
||||
test(S(A()), 0, 1, A());
|
||||
test(S(A()), 1, 0, A());
|
||||
test(S(A()), 1, 1, A());
|
||||
test(S(A()), 1, 2, A());
|
||||
test(S("1", A()), 0, 0, A());
|
||||
test(S("1", A()), 0, 1, A());
|
||||
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 50, 0, A());
|
||||
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 50, 1, A());
|
||||
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 50, 10, A());
|
||||
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 50, 100, A());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user