Home | History | Annotate | Line # | Download | only in experimental
      1  1.1  joerg // -*- C++ -*-
      2  1.1  joerg //===----------------------------- iterator -------------------------------===//
      3  1.1  joerg //
      4  1.1  joerg // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
      5  1.1  joerg // See https://llvm.org/LICENSE.txt for license information.
      6  1.1  joerg // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
      7  1.1  joerg //
      8  1.1  joerg //===----------------------------------------------------------------------===//
      9  1.1  joerg 
     10  1.1  joerg #ifndef _LIBCPP_EXPERIMENTAL_ITERATOR
     11  1.1  joerg #define _LIBCPP_EXPERIMENTAL_ITERATOR
     12  1.1  joerg 
     13  1.1  joerg /*
     14  1.1  joerg namespace std {
     15  1.1  joerg   namespace experimental {
     16  1.1  joerg     inline namespace fundamentals_v2 {
     17  1.1  joerg 
     18  1.1  joerg     template <class DelimT, class charT = char, class traits = char_traits<charT>>
     19  1.1  joerg         class ostream_joiner {
     20  1.1  joerg         public:
     21  1.1  joerg          typedef charT                        char_type;
     22  1.1  joerg          typedef traits                       traits_type;
     23  1.1  joerg          typedef basic_ostream<charT, traits> ostream_type;
     24  1.1  joerg          typedef output_iterator_tag          iterator_category;
     25  1.1  joerg          typedef void                         value_type;
     26  1.1  joerg          typedef void                         difference_type;
     27  1.1  joerg          typedef void                         pointer;
     28  1.1  joerg          typedef void                         reference;
     29  1.1  joerg 
     30  1.1  joerg          ostream_joiner(ostream_type& s, const DelimT& delimiter);
     31  1.1  joerg          ostream_joiner(ostream_type& s, DelimT&& delimiter);
     32  1.1  joerg 
     33  1.1  joerg          template<typename T>
     34  1.1  joerg          ostream_joiner& operator=(const T& value);
     35  1.1  joerg 
     36  1.1  joerg          ostream_joiner& operator*() noexcept;
     37  1.1  joerg          ostream_joiner& operator++() noexcept;
     38  1.1  joerg          ostream_joiner& operator++(int) noexcept;
     39  1.1  joerg    private:
     40  1.1  joerg       ostream_type* out_stream;   // exposition only
     41  1.1  joerg       DelimT delim;               // exposition only
     42  1.1  joerg       bool first_element;         // exposition only
     43  1.1  joerg    };
     44  1.1  joerg 
     45  1.1  joerg   template <class charT, class traits, class DelimT>
     46  1.1  joerg     ostream_joiner<decay_t<DelimT>, charT, traits>
     47  1.1  joerg     make_ostream_joiner(basic_ostream<charT, traits>& os, DelimT&& delimiter);
     48  1.1  joerg 
     49  1.1  joerg     } // inline namespace fundamentals_v2
     50  1.1  joerg   } // namespace experimental
     51  1.1  joerg } // namespace std
     52  1.1  joerg 
     53  1.1  joerg */
     54  1.1  joerg 
     55  1.1  joerg #include <experimental/__config>
     56  1.1  joerg 
     57  1.1  joerg #if _LIBCPP_STD_VER > 11
     58  1.1  joerg 
     59  1.1  joerg #include <iterator>
     60  1.1  joerg 
     61  1.1  joerg _LIBCPP_BEGIN_NAMESPACE_LFTS
     62  1.1  joerg 
     63  1.1  joerg template <class _Delim, class _CharT = char, class _Traits = char_traits<_CharT>>
     64  1.1  joerg class ostream_joiner {
     65  1.1  joerg public:
     66  1.1  joerg 
     67  1.1  joerg     typedef _CharT                               char_type;
     68  1.1  joerg     typedef _Traits                              traits_type;
     69  1.1  joerg     typedef basic_ostream<char_type,traits_type> ostream_type;
     70  1.1  joerg     typedef output_iterator_tag                  iterator_category;
     71  1.1  joerg     typedef void                                 value_type;
     72  1.1  joerg     typedef void                                 difference_type;
     73  1.1  joerg     typedef void                                 pointer;
     74  1.1  joerg     typedef void                                 reference;
     75  1.1  joerg 
     76  1.1  joerg     ostream_joiner(ostream_type& __os, _Delim&& __d)
     77  1.1  joerg         : __output_iter(_VSTD::addressof(__os)), __delim(_VSTD::move(__d)), __first(true) {}
     78  1.1  joerg 
     79  1.1  joerg     ostream_joiner(ostream_type& __os, const _Delim& __d)
     80  1.1  joerg         : __output_iter(_VSTD::addressof(__os)), __delim(__d), __first(true) {}
     81  1.1  joerg 
     82  1.1  joerg 
     83  1.1  joerg     template<typename _Tp>
     84  1.1  joerg     ostream_joiner& operator=(const _Tp& __v)
     85  1.1  joerg     {
     86  1.1  joerg         if (!__first)
     87  1.1  joerg             *__output_iter << __delim;
     88  1.1  joerg         __first = false;
     89  1.1  joerg         *__output_iter << __v;
     90  1.1  joerg         return *this;
     91  1.1  joerg     }
     92  1.1  joerg 
     93  1.1  joerg     ostream_joiner& operator*()     _NOEXCEPT { return *this; }
     94  1.1  joerg     ostream_joiner& operator++()    _NOEXCEPT { return *this; }
     95  1.1  joerg     ostream_joiner& operator++(int) _NOEXCEPT { return *this; }
     96  1.1  joerg 
     97  1.1  joerg private:
     98  1.1  joerg     ostream_type*   __output_iter;
     99  1.1  joerg     _Delim          __delim;
    100  1.1  joerg     bool            __first;
    101  1.1  joerg };
    102  1.1  joerg 
    103  1.1  joerg 
    104  1.1  joerg template <class _CharT, class _Traits, class _Delim>
    105  1.1  joerg ostream_joiner<typename decay<_Delim>::type, _CharT, _Traits>
    106  1.1  joerg make_ostream_joiner(basic_ostream<_CharT, _Traits>& __os, _Delim && __d)
    107  1.1  joerg { return ostream_joiner<typename decay<_Delim>::type, _CharT, _Traits>(__os, _VSTD::forward<_Delim>(__d)); }
    108  1.1  joerg 
    109  1.1  joerg _LIBCPP_END_NAMESPACE_LFTS
    110  1.1  joerg 
    111  1.1  joerg #endif /* _LIBCPP_STD_VER > 11 */
    112  1.1  joerg 
    113  1.1  joerg #endif // _LIBCPP_EXPERIMENTAL_ITERATOR
    114