1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 // UNSUPPORTED: c++03, c++11
10 // UNSUPPORTED: no-localization
11
12 // <experimental/iterator>
13 //
14 // template <class _Delim, class _CharT = char, class _Traits = char_traits<_CharT>>
15 // class ostream_joiner;
16 //
17 // template <class _CharT, class _Traits, class _Delim>
18 // ostream_joiner<typename decay<_Delim>::type, _CharT, _Traits>
19 // make_ostream_joiner(basic_ostream<_CharT, _Traits>& __os, _Delim && __d);
20 //
21
22 #include <experimental/iterator>
23 #include <iostream>
24 #include <sstream>
25 #include <cassert>
26
27 #include "test_macros.h"
28 #include "test_iterators.h"
29
30 namespace exper = std::experimental;
31
32 template <class Delim, class Iter, class CharT = char, class Traits = std::char_traits<CharT>>
test(Delim && d,Iter first,Iter last,const CharT * expected)33 void test (Delim &&d, Iter first, Iter last, const CharT *expected ) {
34 std::basic_stringstream<CharT, Traits> sstream;
35 auto joiner = exper::make_ostream_joiner(sstream, d);
36 typedef exper::ostream_joiner<typename std::decay<Delim>::type, CharT, Traits> Joiner;
37 static_assert((std::is_same<decltype(joiner), Joiner>::value), "" );
38 while (first != last)
39 joiner = *first++;
40 assert(sstream.str() == expected);
41 }
42
main(int,char **)43 int main(int, char**) {
44 const char chars[] = "0123456789";
45 const int ints [] = { 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 };
46
47 // There are more of these tests in another file.
48 // This is just to make sure that the ostream_joiner is created correctly
49 test('X', chars, chars+10, "0X1X2X3X4X5X6X7X8X9");
50 test('x', ints, ints+10, "10x11x12x13x14x15x16x17x18x19");
51 test("Z", chars, chars+10, "0Z1Z2Z3Z4Z5Z6Z7Z8Z9");
52 test("z", ints, ints+10, "10z11z12z13z14z15z16z17z18z19");
53
54 return 0;
55 }
56