libstdc++: iterator Source File

libstdc++

experimental/iterator
Go to the documentation of this file.
1// <experimental/iterator> -*- C++ -*-
2
3// Copyright (C) 2015-2026 Free Software Foundation, Inc.
4//
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 3, or (at your option)
9// any later version.
10
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// Under Section 7 of GPL version 3, you are granted additional
17// permissions described in the GCC Runtime Library Exception, version
18// 3.1, as published by the Free Software Foundation.
19
20// You should have received a copy of the GNU General Public License and
21// a copy of the GCC Runtime Library Exception along with this program;
22// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23// <http://www.gnu.org/licenses/>.
24
25/** @file experimental/iterator
26 * This is a TS C++ Library header.
27 * @ingroup libfund-ts
28 */
29
30//
31// N4336 Working Draft, C++ Extensions for Library Fundamentals, Version 2
32//
33
34#ifndef _GLIBCXX_EXPERIMENTAL_ITERATOR
35#define _GLIBCXX_EXPERIMENTAL_ITERATOR 1
36
37#ifdef _GLIBCXX_SYSHDR
38#pragma GCC system_header
39#endif
40
41#include <bits/requires_hosted.h> // experimental is currently omitted
42
43#if __cplusplus >= 201402L
44
45#include <iterator>
46#include <iosfwd>
47#include <experimental/type_traits>
48
49namespace std _GLIBCXX_VISIBILITY(default)
50{
51_GLIBCXX_BEGIN_NAMESPACE_VERSION
52
53namespace experimental
54{
55inline namespace fundamentals_v2
56{
57#define __cpp_lib_experimental_ostream_joiner 201411
58
59 /// Output iterator that inserts a delimiter between elements.
60 template<typename _DelimT, typename _CharT = char,
61 typename _Traits = char_traits<_CharT>>
62 class ostream_joiner
63 {
64 public:
65 typedef _CharT char_type;
66 typedef _Traits traits_type;
67 typedef basic_ostream<_CharT, _Traits> ostream_type;
68 typedef output_iterator_tag iterator_category;
69 typedef void value_type;
70 typedef void difference_type;
71 typedef void pointer;
72 typedef void reference;
73
74 ostream_joiner(ostream_type& __os, const _DelimT& __delimiter)
75 noexcept(is_nothrow_copy_constructible_v<_DelimT>)
76 : _M_out(std::__addressof(__os)), _M_delim(__delimiter)
77 { }
78
79 ostream_joiner(ostream_type& __os, _DelimT&& __delimiter)
80 noexcept(is_nothrow_move_constructible_v<_DelimT>)
81 : _M_out(std::__addressof(__os)), _M_delim(std::move(__delimiter))
82 { }
83
84 template<typename _Tp>
85 ostream_joiner&
86 operator=(const _Tp& __value)
87 {
88 if (!_M_first)
89 *_M_out << _M_delim;
90 _M_first = false;
91 *_M_out << __value;
92 return *this;
93 }
94
95 ostream_joiner& operator*() noexcept { return *this; }
96 ostream_joiner& operator++() noexcept { return *this; }
97 ostream_joiner& operator++(int) noexcept { return *this; }
98
99 private:
100 ostream_type* _M_out;
101 _DelimT _M_delim;
102 bool _M_first = true;
103 };
104
105 /// Object generator for ostream_joiner.
106 template<typename _CharT, typename _Traits, typename _DelimT>
107 inline ostream_joiner<decay_t<_DelimT>, _CharT, _Traits>
108 make_ostream_joiner(basic_ostream<_CharT, _Traits>& __os,
109 _DelimT&& __delimiter)
110 { return { __os, std::forward<_DelimT>(__delimiter) }; }
111} // namespace fundamentals_v2
112} // namespace experimental
113
114_GLIBCXX_END_NAMESPACE_VERSION
115} // namespace std
116
117#endif // __cplusplus <= 201103L
118
119#endif // _GLIBCXX_EXPERIMENTAL_ITERATOR
iosfwd
requires_hosted.h
std::move
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
Definition move.h:138
std::__addressof
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
Definition move.h:52
std::forward
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
Definition move.h:72
std
ISO C++ entities toplevel namespace is std.
std::experimental
Namespace for features defined in ISO Technical Specifications.
std::experimental::fundamentals_v2::make_ostream_joiner
ostream_joiner< decay_t< _DelimT >, _CharT, _Traits > make_ostream_joiner(basic_ostream< _CharT, _Traits > &__os, _DelimT &&__delimiter)
Object generator for ostream_joiner.
Definition experimental/iterator:108
std::basic_ostream
Template class basic_ostream.
Definition ostream.h:72
std::output_iterator_tag
Marking output iterators.
Definition stl_iterator_base_types.h:100
std::experimental::fundamentals_v2::ostream_joiner
Output iterator that inserts a delimiter between elements.
Definition experimental/iterator:63
iterator
type_traits