diff options
author | paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2001-12-28 14:00:18 +0000 |
---|---|---|
committer | paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2001-12-28 14:00:18 +0000 |
commit | fa69eaa467c3338ddf1b8063050be72fae7c421f (patch) | |
tree | 7708534d0c4ac2441602a8463a62122c1c96af22 /libstdc++-v3/testsuite | |
parent | 66e333b19dd684c799dc6fc81e183dee40625ea7 (diff) |
2001-12-28 Paolo Carlini <pcarlini@unitus.it>
Nathan Myers <ncm@cantrip.org>
* include/bits/basic_string.h (insert(__pos, __s, __n)):
Optimize by avoiding temporaries and working in-place when possible.
(insert(__pos1, __str)): Call insert(__pos1, __str, __pos2, __n).
(insert(__pos1, __str, __pos2, __n)): Call insert(__pos, __s, __n).
* testsuite/21_strings/insert.cc (test02): New testcases.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@48345 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/testsuite')
-rw-r--r-- | libstdc++-v3/testsuite/21_strings/insert.cc | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/21_strings/insert.cc b/libstdc++-v3/testsuite/21_strings/insert.cc index 3c8dff0d5dc..e6140ac2e9b 100644 --- a/libstdc++-v3/testsuite/21_strings/insert.cc +++ b/libstdc++-v3/testsuite/21_strings/insert.cc @@ -187,9 +187,67 @@ int test01(void) return test; } +// Once more +// string& insert(size_type __p, const char* s, size_type n); +// string& insert(size_type __p, const char* s); +// but now s points inside the _Rep +int test02(void) +{ + bool test = true; + + std::string str01; + const char* title = "Everything was beautiful, and nothing hurt"; + // Increasing size: str01 is reallocated every time. + str01 = title; + str01.insert(0, str01.c_str() + str01.size() - 4, 4); + VERIFY( str01 == "hurtEverything was beautiful, and nothing hurt" ); + str01 = title; + str01.insert(0, str01.c_str(), 5); + VERIFY( str01 == "EveryEverything was beautiful, and nothing hurt" ); + str01 = title; + str01.insert(10, str01.c_str() + 4, 6); + VERIFY( str01 == "Everythingything was beautiful, and nothing hurt" ); + str01 = title; + str01.insert(15, str01.c_str(), 10); + VERIFY( str01 == "Everything was Everythingbeautiful, and nothing hurt" ); + str01 = title; + str01.insert(15, str01.c_str() + 11, 13); + VERIFY( str01 == "Everything was was beautifulbeautiful, and nothing hurt" ); + str01 = title; + str01.insert(0, str01.c_str()); + VERIFY( str01 == "Everything was beautiful, and nothing hurt" + "Everything was beautiful, and nothing hurt"); + // Again: no reallocations. + str01 = title; + str01.insert(0, str01.c_str() + str01.size() - 4, 4); + VERIFY( str01 == "hurtEverything was beautiful, and nothing hurt" ); + str01 = title; + str01.insert(0, str01.c_str(), 5); + VERIFY( str01 == "EveryEverything was beautiful, and nothing hurt" ); + str01 = title; + str01.insert(10, str01.c_str() + 4, 6); + VERIFY( str01 == "Everythingything was beautiful, and nothing hurt" ); + str01 = title; + str01.insert(15, str01.c_str(), 10); + VERIFY( str01 == "Everything was Everythingbeautiful, and nothing hurt" ); + str01 = title; + str01.insert(15, str01.c_str() + 11, 13); + VERIFY( str01 == "Everything was was beautifulbeautiful, and nothing hurt" ); + str01 = title; + str01.insert(0, str01.c_str()); + VERIFY( str01 == "Everything was beautiful, and nothing hurt" + "Everything was beautiful, and nothing hurt"); + +#ifdef DEBUG_ASSERT + assert(test); +#endif + return test; +} + int main() { __set_testsuite_memlimit(); test01(); + test02(); return 0; } |