| 1 |
// 1999-07-01 bkoz |
| 2 |
|
| 3 |
// Copyright (C) 1999-2025 Free Software Foundation, Inc. |
| 4 |
// |
| 5 |
// This file is part of the GNU ISO C++ Library. This library is free |
| 6 |
// software; you can redistribute it and/or modify it under the |
| 7 |
// terms of the GNU General Public License as published by the |
| 8 |
// Free Software Foundation; either version 3, or (at your option) |
| 9 |
// any later version. |
| 10 |
|
| 11 |
// This library is distributed in the hope that it will be useful, |
| 12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
// GNU General Public License for more details. |
| 15 |
|
| 16 |
// You should have received a copy of the GNU General Public License along |
| 17 |
// with this library; see the file COPYING3. If not see |
| 18 |
// <http://www.gnu.org/licenses/>. |
| 19 |
|
| 20 |
// 21.3.7.9 inserters and extractors |
| 21 |
|
| 22 |
// NB: This file is predicated on sstreams, istreams, and ostreams |
| 23 |
// working, not to mention other major details like char_traits, and |
| 24 |
// all of the string class. |
| 25 |
|
| 26 |
#include <string> |
| 27 |
#include <sstream> |
| 28 |
#include <testsuite_hooks.h> |
| 29 |
|
| 30 |
// istringstream/stringbuf extractor properly size buffer based on |
| 31 |
// actual, not allocated contents (string.size() vs. string.capacity()). |
| 32 |
// http://gcc.gnu.org/ml/libstdc++/1999-q4/msg00049.html |
| 33 |
void test06(void) |
| 34 |
{ |
| 35 |
typedef std::wstring::size_type size_type; |
| 36 |
std::wstring str01(L"@silent"); |
| 37 |
size_type i01 = str01.size(); |
| 38 |
size_type i02 = str01.capacity(); |
| 39 |
str01.erase(0, 1); |
| 40 |
size_type i03 = str01.size(); |
| 41 |
size_type i04 = str01.capacity(); |
| 42 |
VERIFY( i01 - 1 == i03 ); |
| 43 |
VERIFY( i02 >= i04 ); |
| 44 |
|
| 45 |
std::wistringstream is(str01); |
| 46 |
std::wstring str02; |
| 47 |
is >> str02 >> std::ws; |
| 48 |
size_type i05 = str02.size(); |
| 49 |
size_type i06 = str02.capacity(); |
| 50 |
VERIFY( i05 == i03 ); |
| 51 |
VERIFY( i06 <= i04 ); |
| 52 |
} |
| 53 |
|
| 54 |
int main() |
| 55 |
{ |
| 56 |
test06(); |
| 57 |
return 0; |
| 58 |
} |