Skip to content

Commit ec2ec24

Browse files
committed
libstdc++: implement std::generator
libstdc++-v3/ChangeLog: * include/Makefile.am: Install std/generator, bits/elements_of.h as freestanding. * include/Makefile.in: Regenerate. * include/bits/version.def: Add __cpp_lib_generator. * include/bits/version.h: Regenerate. * include/precompiled/stdc++.h: Include <generator>. * include/std/ranges: Include bits/elements_of.h * include/bits/elements_of.h: New file. * include/std/generator: New file. * testsuite/24_iterators/range_generators/01.cc: New test. * testsuite/24_iterators/range_generators/02.cc: New test. * testsuite/24_iterators/range_generators/copy.cc: New test. * testsuite/24_iterators/range_generators/except.cc: New test. * testsuite/24_iterators/range_generators/synopsis.cc: New test. * testsuite/24_iterators/range_generators/subrange.cc: New test.
1 parent a6bbaab commit ec2ec24

File tree

14 files changed

+1464
-0
lines changed

14 files changed

+1464
-0
lines changed

libstdc++-v3/include/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ std_freestanding = \
3535
${std_srcdir}/coroutine \
3636
${std_srcdir}/expected \
3737
${std_srcdir}/functional \
38+
${std_srcdir}/generator \
3839
${std_srcdir}/iterator \
3940
${std_srcdir}/limits \
4041
${std_srcdir}/memory \
@@ -123,6 +124,7 @@ bits_freestanding = \
123124
${bits_srcdir}/concept_check.h \
124125
${bits_srcdir}/char_traits.h \
125126
${bits_srcdir}/cpp_type_traits.h \
127+
${bits_srcdir}/elements_of.h \
126128
${bits_srcdir}/enable_special_members.h \
127129
${bits_srcdir}/functexcept.h \
128130
${bits_srcdir}/functional_hash.h \

libstdc++-v3/include/Makefile.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ std_freestanding = \
393393
${std_srcdir}/coroutine \
394394
${std_srcdir}/expected \
395395
${std_srcdir}/functional \
396+
${std_srcdir}/generator \
396397
${std_srcdir}/iterator \
397398
${std_srcdir}/limits \
398399
${std_srcdir}/memory \
@@ -478,6 +479,7 @@ bits_freestanding = \
478479
${bits_srcdir}/concept_check.h \
479480
${bits_srcdir}/char_traits.h \
480481
${bits_srcdir}/cpp_type_traits.h \
482+
${bits_srcdir}/elements_of.h \
481483
${bits_srcdir}/enable_special_members.h \
482484
${bits_srcdir}/functexcept.h \
483485
${bits_srcdir}/functional_hash.h \
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Tag type for yielding ranges rather than values in <generator> -*- C++ -*-
2+
3+
// Copyright (C) 2023 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+
#ifndef _GLIBCXX_BITS_ELEMENTS_OF
26+
#define _GLIBCXX_BITS_ELEMENTS_OF
27+
28+
#pragma GCC system_header
29+
30+
#include <bits/c++config.h>
31+
32+
#include <bits/version.h>
33+
34+
// C++ >= 23 && __glibcxx_coroutine
35+
#if defined(__glibcxx_ranges) && defined(__glibcxx_generator)
36+
#include <bits/ranges_base.h>
37+
#include <bits/memoryfwd.h>
38+
39+
#if _GLIBCXX_HOSTED
40+
# include <bits/allocator.h> // likely desirable if hosted.
41+
#endif // HOSTED
42+
43+
namespace std _GLIBCXX_VISIBILITY(default)
44+
{
45+
_GLIBCXX_BEGIN_NAMESPACE_VERSION
46+
namespace ranges
47+
{
48+
49+
/**
50+
* @ingroup ranges
51+
* @since C++23
52+
* @{
53+
*/
54+
55+
template<range _Range, typename _Alloc = allocator<byte>>
56+
struct elements_of
57+
{
58+
[[no_unique_address]] _Range range;
59+
[[no_unique_address]] _Alloc allocator = _Alloc();
60+
};
61+
62+
template<typename _Range, typename _Alloc = allocator<byte>>
63+
elements_of(_Range&&, _Alloc = _Alloc())
64+
-> elements_of<_Range&&, _Alloc>;
65+
66+
/// @}
67+
}
68+
_GLIBCXX_END_NAMESPACE_VERSION
69+
} // namespace std
70+
71+
#endif // __glibcxx_generator && __glibcxx_ranges
72+
#endif // _GLIBCXX_BITS_ELEMENTS_OF

libstdc++-v3/include/bits/version.def

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1743,6 +1743,15 @@ ftms = {
17431743
};
17441744
};
17451745

1746+
ftms = {
1747+
name = generator;
1748+
values = {
1749+
v = 202207;
1750+
cxxmin = 23;
1751+
extra_cond = "__glibcxx_coroutine";
1752+
};
1753+
};
1754+
17461755
// Standard test specifications.
17471756
stds[97] = ">= 199711L";
17481757
stds[03] = ">= 199711L";

libstdc++-v3/include/bits/version.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2125,4 +2125,15 @@
21252125
#endif /* !defined(__cpp_lib_to_string) && defined(__glibcxx_want_to_string) */
21262126
#undef __glibcxx_want_to_string
21272127

2128+
// from version.def line 1637
2129+
#if !defined(__cpp_lib_generator)
2130+
# if (__cplusplus >= 202302L) && (__glibcxx_coroutine)
2131+
# define __glibcxx_generator 202207L
2132+
# if defined(__glibcxx_want_all) || defined(__glibcxx_want_generator)
2133+
# define __cpp_lib_generator 202207L
2134+
# endif
2135+
# endif
2136+
#endif /* !defined(__cpp_lib_generator) && defined(__glibcxx_want_generator) */
2137+
#undef __glibcxx_want_generator
2138+
21282139
#undef __glibcxx_want_all

libstdc++-v3/include/precompiled/stdc++.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@
222222

223223
#if __cplusplus > 202002L
224224
#include <expected>
225+
#include <generator>
225226
#include <spanstream>
226227
#if __has_include(<stacktrace>)
227228
# include <stacktrace>

0 commit comments

Comments
 (0)