| 1 |
// Copyright (C) 2015-2025 Free Software Foundation, Inc. |
| 2 |
// |
| 3 |
// This file is part of the GNU ISO C++ Library. This library is free |
| 4 |
// software; you can redistribute it and/or modify it under the |
| 5 |
// terms of the GNU General Public License as published by the |
| 6 |
// Free Software Foundation; either version 3, or (at your option) |
| 7 |
// any later version. |
| 8 |
|
| 9 |
// This library is distributed in the hope that it will be useful, |
| 10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
// GNU General Public License for more details. |
| 13 |
|
| 14 |
// You should have received a copy of the GNU General Public License along |
| 15 |
// with this library; see the file COPYING3. If not see |
| 16 |
// <http://www.gnu.org/licenses/>. |
| 17 |
|
| 18 |
// { dg-do run { target c++14 } } |
| 19 |
// { dg-add-options no_pch } |
| 20 |
|
| 21 |
#include <experimental/iterator> |
| 22 |
|
| 23 |
#ifndef __cpp_lib_experimental_ostream_joiner |
| 24 |
# error Feature-test macro is not defined. |
| 25 |
#elif __cpp_lib_experimental_ostream_joiner < 201411 |
| 26 |
# error Feature-test macro has bad value. |
| 27 |
#endif |
| 28 |
|
| 29 |
#include <sstream> |
| 30 |
#include <testsuite_hooks.h> |
| 31 |
|
| 32 |
using std::experimental::ostream_joiner; |
| 33 |
|
| 34 |
void |
| 35 |
test01() |
| 36 |
{ |
| 37 |
std::ostringstream os; |
| 38 |
ostream_joiner<int> joiner{os, 9}; |
| 39 |
for (int i : { 1, 2, 3, 4, 5 }) |
| 40 |
*joiner++ = i; |
| 41 |
VERIFY( os.str() == "192939495" ); |
| 42 |
} |
| 43 |
|
| 44 |
void |
| 45 |
test02() |
| 46 |
{ |
| 47 |
std::ostringstream os; |
| 48 |
ostream_joiner<char> joiner{os, ','}; |
| 49 |
for (int i : { 1, 2, 3, 4, 5 }) |
| 50 |
{ |
| 51 |
*joiner = i; |
| 52 |
++joiner; |
| 53 |
} |
| 54 |
VERIFY( os.str() == "1,2,3,4,5" ); |
| 55 |
} |
| 56 |
|
| 57 |
void |
| 58 |
test03() |
| 59 |
{ |
| 60 |
#if _GLIBCXX_USE_WCHAR_T |
| 61 |
std::wostringstream os; |
| 62 |
ostream_joiner<wchar_t, wchar_t> joiner{os, L','}; |
| 63 |
for (int i : { 1, 2, 3, 4, 5 }) |
| 64 |
*joiner++ = i; |
| 65 |
VERIFY( os.str() == L"1,2,3,4,5" ); |
| 66 |
#endif |
| 67 |
} |
| 68 |
|
| 69 |
int |
| 70 |
main() |
| 71 |
{ |
| 72 |
test01(); |
| 73 |
test02(); |
| 74 |
test03(); |
| 75 |
} |