123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- #ifndef _LIBCPP_EXPERIMENTAL_ITERATOR
- #define _LIBCPP_EXPERIMENTAL_ITERATOR
- #include <experimental/__config>
- #if _LIBCPP_STD_VER > 11
- #include <iterator>
- _LIBCPP_BEGIN_NAMESPACE_LFTS
- template <class _Delim, class _CharT = char, class _Traits = char_traits<_CharT>>
- class ostream_joiner {
- public:
- typedef _CharT char_type;
- typedef _Traits traits_type;
- typedef basic_ostream<char_type,traits_type> ostream_type;
- typedef output_iterator_tag iterator_category;
- typedef void value_type;
- typedef void difference_type;
- typedef void pointer;
- typedef void reference;
- ostream_joiner(ostream_type& __os, _Delim&& __d)
- : __out(_VSTD::addressof(__os)), __delim(_VSTD::move(__d)), __first(true) {}
-
- ostream_joiner(ostream_type& __os, const _Delim& __d)
- : __out(_VSTD::addressof(__os)), __delim(__d), __first(true) {}
-
- template<typename _Tp>
- ostream_joiner& operator=(const _Tp& __v)
- {
- if (!__first)
- *__out << __delim;
- __first = false;
- *__out << __v;
- return *this;
- }
- ostream_joiner& operator*() _NOEXCEPT { return *this; }
- ostream_joiner& operator++() _NOEXCEPT { return *this; }
- ostream_joiner& operator++(int) _NOEXCEPT { return *this; }
- private:
- ostream_type* __out;
- _Delim __delim;
- bool __first;
- };
- template <class _CharT, class _Traits, class _Delim>
- ostream_joiner<typename decay<_Delim>::type, _CharT, _Traits>
- make_ostream_joiner(basic_ostream<_CharT, _Traits>& __os, _Delim && __d)
- { return ostream_joiner<typename decay<_Delim>::type, _CharT, _Traits>(__os, _VSTD::forward<_Delim>(__d)); }
- _LIBCPP_END_NAMESPACE_LFTS
- #endif
- #endif
|