1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // UNSUPPORTED: c++98, c++03, c++11
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 exp = 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 = exp::make_ostream_joiner(sstream, d);
36 typedef exp::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()43 int main () {
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