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:
@@ -18,22 +18,24 @@
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
|
||||
typedef std::string S;
|
||||
#include "../../min_allocator.h"
|
||||
|
||||
template <class S>
|
||||
void
|
||||
test(S s, S::size_type pos1, S::size_type n1, S str, S expected)
|
||||
test(S s, typename S::size_type pos1, typename S::size_type n1, S str, S expected)
|
||||
{
|
||||
S::size_type old_size = s.size();
|
||||
S::const_iterator first = s.begin() + pos1;
|
||||
S::const_iterator last = s.begin() + pos1 + n1;
|
||||
typename S::size_type old_size = s.size();
|
||||
typename S::const_iterator first = s.begin() + pos1;
|
||||
typename S::const_iterator last = s.begin() + pos1 + n1;
|
||||
s.replace(first, last, str);
|
||||
assert(s.__invariants());
|
||||
assert(s == expected);
|
||||
S::size_type xlen = last - first;
|
||||
S::size_type rlen = str.size();
|
||||
typename S::size_type xlen = last - first;
|
||||
typename S::size_type rlen = str.size();
|
||||
assert(s.size() == old_size - xlen + rlen);
|
||||
}
|
||||
|
||||
template <class S>
|
||||
void test0()
|
||||
{
|
||||
test(S(""), 0, 0, S(""), S(""));
|
||||
@@ -138,6 +140,7 @@ void test0()
|
||||
test(S("abcdefghij"), 1, 1, S("12345678901234567890"), S("a12345678901234567890cdefghij"));
|
||||
}
|
||||
|
||||
template <class S>
|
||||
void test1()
|
||||
{
|
||||
test(S("abcdefghij"), 1, 4, S(""), S("afghij"));
|
||||
@@ -242,6 +245,7 @@ void test1()
|
||||
test(S("abcdefghijklmnopqrst"), 10, 9, S("12345678901234567890"), S("abcdefghij12345678901234567890t"));
|
||||
}
|
||||
|
||||
template <class S>
|
||||
void test2()
|
||||
{
|
||||
test(S("abcdefghijklmnopqrst"), 10, 10, S(""), S("abcdefghij"));
|
||||
@@ -264,7 +268,18 @@ void test2()
|
||||
|
||||
int main()
|
||||
{
|
||||
test0();
|
||||
test1();
|
||||
test2();
|
||||
{
|
||||
typedef std::string S;
|
||||
test0<S>();
|
||||
test1<S>();
|
||||
test2<S>();
|
||||
}
|
||||
#if __cplusplus >= 201103L
|
||||
{
|
||||
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
|
||||
test0<S>();
|
||||
test1<S>();
|
||||
test2<S>();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
Reference in New Issue
Block a user