2016-01-28 12:15:35 +08:00
|
|
|
// -*- C++ -*-
|
2021-11-18 05:25:01 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2016-01-28 12:15:35 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2016-01-28 12:15:35 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef _LIBCPP_EXPERIMENTAL_ITERATOR
|
|
|
|
#define _LIBCPP_EXPERIMENTAL_ITERATOR
|
|
|
|
|
|
|
|
/*
|
|
|
|
namespace std {
|
|
|
|
namespace experimental {
|
|
|
|
inline namespace fundamentals_v2 {
|
|
|
|
|
|
|
|
template <class DelimT, class charT = char, class traits = char_traits<charT>>
|
|
|
|
class ostream_joiner {
|
|
|
|
public:
|
|
|
|
typedef charT char_type;
|
|
|
|
typedef traits traits_type;
|
|
|
|
typedef basic_ostream<charT, traits> ostream_type;
|
|
|
|
typedef output_iterator_tag iterator_category;
|
|
|
|
typedef void value_type;
|
|
|
|
typedef void difference_type;
|
|
|
|
typedef void pointer;
|
|
|
|
typedef void reference;
|
2019-10-24 01:40:15 +08:00
|
|
|
|
2016-01-28 12:15:35 +08:00
|
|
|
ostream_joiner(ostream_type& s, const DelimT& delimiter);
|
|
|
|
ostream_joiner(ostream_type& s, DelimT&& delimiter);
|
|
|
|
|
2019-10-24 01:40:15 +08:00
|
|
|
template<typename T>
|
2016-01-28 12:15:35 +08:00
|
|
|
ostream_joiner& operator=(const T& value);
|
|
|
|
|
|
|
|
ostream_joiner& operator*() noexcept;
|
|
|
|
ostream_joiner& operator++() noexcept;
|
|
|
|
ostream_joiner& operator++(int) noexcept;
|
|
|
|
private:
|
2019-10-24 01:40:15 +08:00
|
|
|
ostream_type* out_stream; // exposition only
|
|
|
|
DelimT delim; // exposition only
|
2016-01-28 12:15:35 +08:00
|
|
|
bool first_element; // exposition only
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class charT, class traits, class DelimT>
|
|
|
|
ostream_joiner<decay_t<DelimT>, charT, traits>
|
|
|
|
make_ostream_joiner(basic_ostream<charT, traits>& os, DelimT&& delimiter);
|
|
|
|
|
|
|
|
} // inline namespace fundamentals_v2
|
|
|
|
} // namespace experimental
|
|
|
|
} // namespace std
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2022-03-26 00:55:36 +08:00
|
|
|
#include <__assert> // all public C++ headers provide the assertion handler
|
2021-06-05 10:47:47 +08:00
|
|
|
#include <__memory/addressof.h>
|
|
|
|
#include <__utility/forward.h>
|
2022-01-07 22:45:05 +08:00
|
|
|
#include <__utility/move.h>
|
2021-12-06 02:08:36 +08:00
|
|
|
#include <experimental/__config>
|
2022-04-04 00:40:39 +08:00
|
|
|
#include <iosfwd> // char_traits
|
2016-01-28 12:15:35 +08:00
|
|
|
#include <iterator>
|
|
|
|
|
2021-12-06 02:08:36 +08:00
|
|
|
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
2022-02-02 09:16:40 +08:00
|
|
|
# pragma GCC system_header
|
2021-12-06 02:08:36 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if _LIBCPP_STD_VER > 11
|
|
|
|
|
2016-01-28 12:15:35 +08:00
|
|
|
_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)
|
2017-11-14 19:14:25 +08:00
|
|
|
: __output_iter(_VSTD::addressof(__os)), __delim(_VSTD::move(__d)), __first(true) {}
|
2019-10-24 01:40:15 +08:00
|
|
|
|
2016-01-28 12:15:35 +08:00
|
|
|
ostream_joiner(ostream_type& __os, const _Delim& __d)
|
2017-11-14 19:14:25 +08:00
|
|
|
: __output_iter(_VSTD::addressof(__os)), __delim(__d), __first(true) {}
|
2019-10-24 01:40:15 +08:00
|
|
|
|
2016-01-28 12:15:35 +08:00
|
|
|
|
|
|
|
template<typename _Tp>
|
|
|
|
ostream_joiner& operator=(const _Tp& __v)
|
|
|
|
{
|
|
|
|
if (!__first)
|
2017-11-14 19:14:25 +08:00
|
|
|
*__output_iter << __delim;
|
2016-01-28 12:15:35 +08:00
|
|
|
__first = false;
|
2017-11-14 19:14:25 +08:00
|
|
|
*__output_iter << __v;
|
2016-01-28 12:15:35 +08:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
ostream_joiner& operator*() _NOEXCEPT { return *this; }
|
|
|
|
ostream_joiner& operator++() _NOEXCEPT { return *this; }
|
|
|
|
ostream_joiner& operator++(int) _NOEXCEPT { return *this; }
|
|
|
|
|
|
|
|
private:
|
2017-11-14 19:14:25 +08:00
|
|
|
ostream_type* __output_iter;
|
2016-01-28 12:15:35 +08:00
|
|
|
_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
|
|
|
|
|
2021-12-06 02:08:36 +08:00
|
|
|
#endif // _LIBCPP_STD_VER > 11
|
2016-01-28 12:15:35 +08:00
|
|
|
|
|
|
|
#endif // _LIBCPP_EXPERIMENTAL_ITERATOR
|