1*58b9f456SAndroid Build Coastguard Worker// -*- C++ -*- 2*58b9f456SAndroid Build Coastguard Worker//===----------------------------- iterator -------------------------------===// 3*58b9f456SAndroid Build Coastguard Worker// 4*58b9f456SAndroid Build Coastguard Worker// The LLVM Compiler Infrastructure 5*58b9f456SAndroid Build Coastguard Worker// 6*58b9f456SAndroid Build Coastguard Worker// This file is distributed under the University of Illinois Open Source 7*58b9f456SAndroid Build Coastguard Worker// License. See LICENSE.TXT for details. 8*58b9f456SAndroid Build Coastguard Worker// 9*58b9f456SAndroid Build Coastguard Worker//===----------------------------------------------------------------------===// 10*58b9f456SAndroid Build Coastguard Worker 11*58b9f456SAndroid Build Coastguard Worker#ifndef _LIBCPP_EXPERIMENTAL_ITERATOR 12*58b9f456SAndroid Build Coastguard Worker#define _LIBCPP_EXPERIMENTAL_ITERATOR 13*58b9f456SAndroid Build Coastguard Worker 14*58b9f456SAndroid Build Coastguard Worker/* 15*58b9f456SAndroid Build Coastguard Workernamespace std { 16*58b9f456SAndroid Build Coastguard Worker namespace experimental { 17*58b9f456SAndroid Build Coastguard Worker inline namespace fundamentals_v2 { 18*58b9f456SAndroid Build Coastguard Worker 19*58b9f456SAndroid Build Coastguard Worker template <class DelimT, class charT = char, class traits = char_traits<charT>> 20*58b9f456SAndroid Build Coastguard Worker class ostream_joiner { 21*58b9f456SAndroid Build Coastguard Worker public: 22*58b9f456SAndroid Build Coastguard Worker typedef charT char_type; 23*58b9f456SAndroid Build Coastguard Worker typedef traits traits_type; 24*58b9f456SAndroid Build Coastguard Worker typedef basic_ostream<charT, traits> ostream_type; 25*58b9f456SAndroid Build Coastguard Worker typedef output_iterator_tag iterator_category; 26*58b9f456SAndroid Build Coastguard Worker typedef void value_type; 27*58b9f456SAndroid Build Coastguard Worker typedef void difference_type; 28*58b9f456SAndroid Build Coastguard Worker typedef void pointer; 29*58b9f456SAndroid Build Coastguard Worker typedef void reference; 30*58b9f456SAndroid Build Coastguard Worker 31*58b9f456SAndroid Build Coastguard Worker ostream_joiner(ostream_type& s, const DelimT& delimiter); 32*58b9f456SAndroid Build Coastguard Worker ostream_joiner(ostream_type& s, DelimT&& delimiter); 33*58b9f456SAndroid Build Coastguard Worker 34*58b9f456SAndroid Build Coastguard Worker template<typename T> 35*58b9f456SAndroid Build Coastguard Worker ostream_joiner& operator=(const T& value); 36*58b9f456SAndroid Build Coastguard Worker 37*58b9f456SAndroid Build Coastguard Worker ostream_joiner& operator*() noexcept; 38*58b9f456SAndroid Build Coastguard Worker ostream_joiner& operator++() noexcept; 39*58b9f456SAndroid Build Coastguard Worker ostream_joiner& operator++(int) noexcept; 40*58b9f456SAndroid Build Coastguard Worker private: 41*58b9f456SAndroid Build Coastguard Worker ostream_type* out_stream; // exposition only 42*58b9f456SAndroid Build Coastguard Worker DelimT delim; // exposition only 43*58b9f456SAndroid Build Coastguard Worker bool first_element; // exposition only 44*58b9f456SAndroid Build Coastguard Worker }; 45*58b9f456SAndroid Build Coastguard Worker 46*58b9f456SAndroid Build Coastguard Worker template <class charT, class traits, class DelimT> 47*58b9f456SAndroid Build Coastguard Worker ostream_joiner<decay_t<DelimT>, charT, traits> 48*58b9f456SAndroid Build Coastguard Worker make_ostream_joiner(basic_ostream<charT, traits>& os, DelimT&& delimiter); 49*58b9f456SAndroid Build Coastguard Worker 50*58b9f456SAndroid Build Coastguard Worker } // inline namespace fundamentals_v2 51*58b9f456SAndroid Build Coastguard Worker } // namespace experimental 52*58b9f456SAndroid Build Coastguard Worker} // namespace std 53*58b9f456SAndroid Build Coastguard Worker 54*58b9f456SAndroid Build Coastguard Worker*/ 55*58b9f456SAndroid Build Coastguard Worker 56*58b9f456SAndroid Build Coastguard Worker#include <experimental/__config> 57*58b9f456SAndroid Build Coastguard Worker 58*58b9f456SAndroid Build Coastguard Worker#if _LIBCPP_STD_VER > 11 59*58b9f456SAndroid Build Coastguard Worker 60*58b9f456SAndroid Build Coastguard Worker#include <iterator> 61*58b9f456SAndroid Build Coastguard Worker 62*58b9f456SAndroid Build Coastguard Worker_LIBCPP_BEGIN_NAMESPACE_LFTS 63*58b9f456SAndroid Build Coastguard Worker 64*58b9f456SAndroid Build Coastguard Workertemplate <class _Delim, class _CharT = char, class _Traits = char_traits<_CharT>> 65*58b9f456SAndroid Build Coastguard Workerclass ostream_joiner { 66*58b9f456SAndroid Build Coastguard Workerpublic: 67*58b9f456SAndroid Build Coastguard Worker 68*58b9f456SAndroid Build Coastguard Worker typedef _CharT char_type; 69*58b9f456SAndroid Build Coastguard Worker typedef _Traits traits_type; 70*58b9f456SAndroid Build Coastguard Worker typedef basic_ostream<char_type,traits_type> ostream_type; 71*58b9f456SAndroid Build Coastguard Worker typedef output_iterator_tag iterator_category; 72*58b9f456SAndroid Build Coastguard Worker typedef void value_type; 73*58b9f456SAndroid Build Coastguard Worker typedef void difference_type; 74*58b9f456SAndroid Build Coastguard Worker typedef void pointer; 75*58b9f456SAndroid Build Coastguard Worker typedef void reference; 76*58b9f456SAndroid Build Coastguard Worker 77*58b9f456SAndroid Build Coastguard Worker ostream_joiner(ostream_type& __os, _Delim&& __d) 78*58b9f456SAndroid Build Coastguard Worker : __output_iter(_VSTD::addressof(__os)), __delim(_VSTD::move(__d)), __first(true) {} 79*58b9f456SAndroid Build Coastguard Worker 80*58b9f456SAndroid Build Coastguard Worker ostream_joiner(ostream_type& __os, const _Delim& __d) 81*58b9f456SAndroid Build Coastguard Worker : __output_iter(_VSTD::addressof(__os)), __delim(__d), __first(true) {} 82*58b9f456SAndroid Build Coastguard Worker 83*58b9f456SAndroid Build Coastguard Worker 84*58b9f456SAndroid Build Coastguard Worker template<typename _Tp> 85*58b9f456SAndroid Build Coastguard Worker ostream_joiner& operator=(const _Tp& __v) 86*58b9f456SAndroid Build Coastguard Worker { 87*58b9f456SAndroid Build Coastguard Worker if (!__first) 88*58b9f456SAndroid Build Coastguard Worker *__output_iter << __delim; 89*58b9f456SAndroid Build Coastguard Worker __first = false; 90*58b9f456SAndroid Build Coastguard Worker *__output_iter << __v; 91*58b9f456SAndroid Build Coastguard Worker return *this; 92*58b9f456SAndroid Build Coastguard Worker } 93*58b9f456SAndroid Build Coastguard Worker 94*58b9f456SAndroid Build Coastguard Worker ostream_joiner& operator*() _NOEXCEPT { return *this; } 95*58b9f456SAndroid Build Coastguard Worker ostream_joiner& operator++() _NOEXCEPT { return *this; } 96*58b9f456SAndroid Build Coastguard Worker ostream_joiner& operator++(int) _NOEXCEPT { return *this; } 97*58b9f456SAndroid Build Coastguard Worker 98*58b9f456SAndroid Build Coastguard Workerprivate: 99*58b9f456SAndroid Build Coastguard Worker ostream_type* __output_iter; 100*58b9f456SAndroid Build Coastguard Worker _Delim __delim; 101*58b9f456SAndroid Build Coastguard Worker bool __first; 102*58b9f456SAndroid Build Coastguard Worker}; 103*58b9f456SAndroid Build Coastguard Worker 104*58b9f456SAndroid Build Coastguard Worker 105*58b9f456SAndroid Build Coastguard Workertemplate <class _CharT, class _Traits, class _Delim> 106*58b9f456SAndroid Build Coastguard Workerostream_joiner<typename decay<_Delim>::type, _CharT, _Traits> 107*58b9f456SAndroid Build Coastguard Workermake_ostream_joiner(basic_ostream<_CharT, _Traits>& __os, _Delim && __d) 108*58b9f456SAndroid Build Coastguard Worker{ return ostream_joiner<typename decay<_Delim>::type, _CharT, _Traits>(__os, _VSTD::forward<_Delim>(__d)); } 109*58b9f456SAndroid Build Coastguard Worker 110*58b9f456SAndroid Build Coastguard Worker_LIBCPP_END_NAMESPACE_LFTS 111*58b9f456SAndroid Build Coastguard Worker 112*58b9f456SAndroid Build Coastguard Worker#endif /* _LIBCPP_STD_VER > 11 */ 113*58b9f456SAndroid Build Coastguard Worker 114*58b9f456SAndroid Build Coastguard Worker#endif // _LIBCPP_EXPERIMENTAL_ITERATOR 115