17c82a1ecSDimitry Andric// -*- C++ -*- 27c82a1ecSDimitry Andric//===----------------------------- iterator -------------------------------===// 37c82a1ecSDimitry Andric// 47c82a1ecSDimitry Andric// The LLVM Compiler Infrastructure 57c82a1ecSDimitry Andric// 67c82a1ecSDimitry Andric// This file is distributed under the University of Illinois Open Source 77c82a1ecSDimitry Andric// License. See LICENSE.TXT for details. 87c82a1ecSDimitry Andric// 97c82a1ecSDimitry Andric//===----------------------------------------------------------------------===// 107c82a1ecSDimitry Andric 117c82a1ecSDimitry Andric#ifndef _LIBCPP_EXPERIMENTAL_ITERATOR 127c82a1ecSDimitry Andric#define _LIBCPP_EXPERIMENTAL_ITERATOR 137c82a1ecSDimitry Andric 147c82a1ecSDimitry Andric/* 157c82a1ecSDimitry Andricnamespace std { 167c82a1ecSDimitry Andric namespace experimental { 177c82a1ecSDimitry Andric inline namespace fundamentals_v2 { 187c82a1ecSDimitry Andric 197c82a1ecSDimitry Andric template <class DelimT, class charT = char, class traits = char_traits<charT>> 207c82a1ecSDimitry Andric class ostream_joiner { 217c82a1ecSDimitry Andric public: 227c82a1ecSDimitry Andric typedef charT char_type; 237c82a1ecSDimitry Andric typedef traits traits_type; 247c82a1ecSDimitry Andric typedef basic_ostream<charT, traits> ostream_type; 257c82a1ecSDimitry Andric typedef output_iterator_tag iterator_category; 267c82a1ecSDimitry Andric typedef void value_type; 277c82a1ecSDimitry Andric typedef void difference_type; 287c82a1ecSDimitry Andric typedef void pointer; 297c82a1ecSDimitry Andric typedef void reference; 307c82a1ecSDimitry Andric 317c82a1ecSDimitry Andric ostream_joiner(ostream_type& s, const DelimT& delimiter); 327c82a1ecSDimitry Andric ostream_joiner(ostream_type& s, DelimT&& delimiter); 337c82a1ecSDimitry Andric 347c82a1ecSDimitry Andric template<typename T> 357c82a1ecSDimitry Andric ostream_joiner& operator=(const T& value); 367c82a1ecSDimitry Andric 377c82a1ecSDimitry Andric ostream_joiner& operator*() noexcept; 387c82a1ecSDimitry Andric ostream_joiner& operator++() noexcept; 397c82a1ecSDimitry Andric ostream_joiner& operator++(int) noexcept; 407c82a1ecSDimitry Andric private: 417c82a1ecSDimitry Andric ostream_type* out_stream; // exposition only 427c82a1ecSDimitry Andric DelimT delim; // exposition only 437c82a1ecSDimitry Andric bool first_element; // exposition only 447c82a1ecSDimitry Andric }; 457c82a1ecSDimitry Andric 467c82a1ecSDimitry Andric template <class charT, class traits, class DelimT> 477c82a1ecSDimitry Andric ostream_joiner<decay_t<DelimT>, charT, traits> 487c82a1ecSDimitry Andric make_ostream_joiner(basic_ostream<charT, traits>& os, DelimT&& delimiter); 497c82a1ecSDimitry Andric 507c82a1ecSDimitry Andric } // inline namespace fundamentals_v2 517c82a1ecSDimitry Andric } // namespace experimental 527c82a1ecSDimitry Andric} // namespace std 537c82a1ecSDimitry Andric 547c82a1ecSDimitry Andric*/ 557c82a1ecSDimitry Andric 567c82a1ecSDimitry Andric#include <experimental/__config> 577c82a1ecSDimitry Andric 587c82a1ecSDimitry Andric#if _LIBCPP_STD_VER > 11 597c82a1ecSDimitry Andric 607c82a1ecSDimitry Andric#include <iterator> 617c82a1ecSDimitry Andric 627c82a1ecSDimitry Andric_LIBCPP_BEGIN_NAMESPACE_LFTS 637c82a1ecSDimitry Andric 647c82a1ecSDimitry Andrictemplate <class _Delim, class _CharT = char, class _Traits = char_traits<_CharT>> 657c82a1ecSDimitry Andricclass ostream_joiner { 667c82a1ecSDimitry Andricpublic: 677c82a1ecSDimitry Andric 687c82a1ecSDimitry Andric typedef _CharT char_type; 697c82a1ecSDimitry Andric typedef _Traits traits_type; 707c82a1ecSDimitry Andric typedef basic_ostream<char_type,traits_type> ostream_type; 717c82a1ecSDimitry Andric typedef output_iterator_tag iterator_category; 727c82a1ecSDimitry Andric typedef void value_type; 737c82a1ecSDimitry Andric typedef void difference_type; 747c82a1ecSDimitry Andric typedef void pointer; 757c82a1ecSDimitry Andric typedef void reference; 767c82a1ecSDimitry Andric 777c82a1ecSDimitry Andric ostream_joiner(ostream_type& __os, _Delim&& __d) 78*b2c7081bSDimitry Andric : __output_iter(_VSTD::addressof(__os)), __delim(_VSTD::move(__d)), __first(true) {} 797c82a1ecSDimitry Andric 807c82a1ecSDimitry Andric ostream_joiner(ostream_type& __os, const _Delim& __d) 81*b2c7081bSDimitry Andric : __output_iter(_VSTD::addressof(__os)), __delim(__d), __first(true) {} 827c82a1ecSDimitry Andric 837c82a1ecSDimitry Andric 847c82a1ecSDimitry Andric template<typename _Tp> 857c82a1ecSDimitry Andric ostream_joiner& operator=(const _Tp& __v) 867c82a1ecSDimitry Andric { 877c82a1ecSDimitry Andric if (!__first) 88*b2c7081bSDimitry Andric *__output_iter << __delim; 897c82a1ecSDimitry Andric __first = false; 90*b2c7081bSDimitry Andric *__output_iter << __v; 917c82a1ecSDimitry Andric return *this; 927c82a1ecSDimitry Andric } 937c82a1ecSDimitry Andric 947c82a1ecSDimitry Andric ostream_joiner& operator*() _NOEXCEPT { return *this; } 957c82a1ecSDimitry Andric ostream_joiner& operator++() _NOEXCEPT { return *this; } 967c82a1ecSDimitry Andric ostream_joiner& operator++(int) _NOEXCEPT { return *this; } 977c82a1ecSDimitry Andric 987c82a1ecSDimitry Andricprivate: 99*b2c7081bSDimitry Andric ostream_type* __output_iter; 1007c82a1ecSDimitry Andric _Delim __delim; 1017c82a1ecSDimitry Andric bool __first; 1027c82a1ecSDimitry Andric}; 1037c82a1ecSDimitry Andric 1047c82a1ecSDimitry Andric 1057c82a1ecSDimitry Andrictemplate <class _CharT, class _Traits, class _Delim> 1067c82a1ecSDimitry Andricostream_joiner<typename decay<_Delim>::type, _CharT, _Traits> 1077c82a1ecSDimitry Andricmake_ostream_joiner(basic_ostream<_CharT, _Traits>& __os, _Delim && __d) 1087c82a1ecSDimitry Andric{ return ostream_joiner<typename decay<_Delim>::type, _CharT, _Traits>(__os, _VSTD::forward<_Delim>(__d)); } 1097c82a1ecSDimitry Andric 1107c82a1ecSDimitry Andric_LIBCPP_END_NAMESPACE_LFTS 1117c82a1ecSDimitry Andric 1127c82a1ecSDimitry Andric#endif /* _LIBCPP_STD_VER > 11 */ 1137c82a1ecSDimitry Andric 1147c82a1ecSDimitry Andric#endif // _LIBCPP_EXPERIMENTAL_ITERATOR 115