]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/experimental/iterator/ostream_joiner.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / experimental / iterator / ostream_joiner.cc
1 // Copyright (C) 2015-2020 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
20 #include <experimental/iterator>
21 #include <sstream>
22 #include <testsuite_hooks.h>
23
24 #ifndef __cpp_lib_experimental_ostream_joiner
25 # error Feature-test macro is not defined.
26 #elif __cpp_lib_experimental_ostream_joiner < 201411
27 # error Feature-test macro has bad value.
28 #endif
29
30 using std::experimental::ostream_joiner;
31
32 void
33 test01()
34 {
35 std::ostringstream os;
36 ostream_joiner<int> joiner{os, 9};
37 for (int i : { 1, 2, 3, 4, 5 })
38 *joiner++ = i;
39 VERIFY( os.str() == "192939495" );
40 }
41
42 void
43 test02()
44 {
45 std::ostringstream os;
46 ostream_joiner<char> joiner{os, ','};
47 for (int i : { 1, 2, 3, 4, 5 })
48 {
49 *joiner = i;
50 ++joiner;
51 }
52 VERIFY( os.str() == "1,2,3,4,5" );
53 }
54
55 void
56 test03()
57 {
58 #if _GLIBCXX_USE_WCHAR_T
59 std::wostringstream os;
60 ostream_joiner<wchar_t, wchar_t> joiner{os, L','};
61 for (int i : { 1, 2, 3, 4, 5 })
62 *joiner++ = i;
63 VERIFY( os.str() == L"1,2,3,4,5" );
64 #endif
65 }
66
67 int
68 main()
69 {
70 test01();
71 test02();
72 test03();
73 }