Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generator WIP #4342

Merged
merged 8 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions stl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ set(HEADERS
${CMAKE_CURRENT_LIST_DIR}/inc/fstream
${CMAKE_CURRENT_LIST_DIR}/inc/functional
${CMAKE_CURRENT_LIST_DIR}/inc/future
${CMAKE_CURRENT_LIST_DIR}/inc/generator
${CMAKE_CURRENT_LIST_DIR}/inc/hash_map
${CMAKE_CURRENT_LIST_DIR}/inc/hash_set
${CMAKE_CURRENT_LIST_DIR}/inc/header-units.json
Expand Down
1 change: 1 addition & 0 deletions stl/inc/__msvc_all_public_headers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
#include <forward_list>
#include <fstream>
#include <functional>
#include <generator>
#include <hash_map>
#include <hash_set>
#include <iomanip>
Expand Down
472 changes: 472 additions & 0 deletions stl/inc/generator

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions stl/inc/header-units.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"fstream",
"functional",
"future",
"generator",
// "hash_map", // non-Standard, will be removed soon
// "hash_set", // non-Standard, will be removed soon
"initializer_list",
Expand Down
15 changes: 15 additions & 0 deletions stl/inc/ranges
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,21 @@ namespace ranges {
template <class _Ty, size_t _Extent>
requires (_Extent != dynamic_extent)
inline constexpr auto _Compile_time_max_size<const span<_Ty, _Extent>> = _Extent;

#ifdef __cpp_lib_byte
using _Elements_alloc_type = byte;
#else
using _Elements_alloc_type = char;
#endif
Comment on lines +81 to +85
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, perhaps we should be consistent on whether there's workaround when __cpp_lib_byte is not defined, see #4337 (comment).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is different than our previous __cpp_lib_byte checks, and is ODR-violation-ish.

Really we need to push for the WinSDK to be fixed, but in the meantime we should definitely think about what to do here.


_EXPORT_STD template <range _Rng, class _Alloc = allocator<_Elements_alloc_type>>
struct elements_of {
/* [[no_unique_address]] */ _Rng range;
/* [[no_unique_address]] */ _Alloc allocator{};
};

template <class _Rng, class _Alloc = allocator<_Elements_alloc_type>>
elements_of(_Rng&&, _Alloc = {}) -> elements_of<_Rng&&, _Alloc>;
#endif // _HAS_CXX23

// clang-format off
Expand Down
8 changes: 7 additions & 1 deletion stl/inc/yvals_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@
// P2474R2 views::repeat
// P2494R2 Relaxing Range Adaptors To Allow Move-Only Types
// P2499R0 string_view Range Constructor Should Be explicit
// P2502R2 <generator>: Synchronous Coroutine Generator For Ranges
// P2505R5 Monadic Functions For expected
// P2539R4 Synchronizing print() With The Underlying Stream
// P2540R1 Empty Product For Certain Views
Expand Down Expand Up @@ -1833,7 +1834,12 @@ _EMIT_STL_ERROR(STL1004, "C++98 unexpected() is incompatible with C++23 unexpect
#define __cpp_lib_formatters 202302L
#endif // defined(__cpp_lib_concepts)

#define __cpp_lib_forward_like 202207L
#define __cpp_lib_forward_like 202207L

#if defined(__cpp_lib_concepts) && defined(__cpp_lib_byte) && defined(__cpp_impl_coroutine)
#define __cpp_lib_generator 202207L
#endif // defined(__cpp_lib_concepts) && defined(__cpp_lib_byte) && defined(__cpp_impl_coroutine)

#define __cpp_lib_invoke_r 202106L
#define __cpp_lib_ios_noreplace 202207L
#define __cpp_lib_is_scoped_enum 202011L
Expand Down
1 change: 1 addition & 0 deletions stl/modules/std.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export module std;
#include <fstream>
#include <functional>
#include <future>
#include <generator>
#include <initializer_list>
#include <iomanip>
#include <ios>
Expand Down
17 changes: 17 additions & 0 deletions tests/std/include/test_header_units_and_modules.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,20 @@ void test_future() {
assert(f.get() == 1729);
}

#if TEST_STANDARD >= 23
void test_generator() {
using namespace std;
puts("Testing <generator>.");
auto some_ints = [](int hi) -> generator<int> {
for (int i = 0; i < hi; ++i) {
co_yield i;
}
};
constexpr int bound = 42;
assert(ranges::equal(some_ints(bound), views::iota(0, bound)));
}
#endif // TEST_STANDARD >= 23

void test_initializer_list() {
using namespace std;
puts("Testing <initializer_list>.");
Expand Down Expand Up @@ -1145,6 +1159,9 @@ void all_cpp_header_tests() {
test_fstream();
test_functional();
test_future();
#if TEST_STANDARD >= 23
test_generator();
#endif // TEST_STANDARD >= 23
test_initializer_list();
test_iomanip();
test_ios();
Expand Down
1 change: 1 addition & 0 deletions tests/std/test.lst
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,7 @@ tests\P2467R1_exclusive_mode_fstreams
tests\P2474R2_views_repeat
tests\P2474R2_views_repeat_death
tests\P2494R2_move_only_range_adaptors
tests\P2502R2_generator
tests\P2505R5_monadic_functions_for_std_expected
tests\P2510R3_text_formatting_pointers
tests\P2517R1_apply_conditional_noexcept
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"fstream",
"functional",
"future",
"generator",
"initializer_list",
"iomanip",
"ios",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import <forward_list>;
import <fstream>;
import <functional>;
import <future>;
import <generator>;
import <initializer_list>;
import <iomanip>;
import <ios>;
Expand Down
4 changes: 4 additions & 0 deletions tests/std/tests/P2502R2_generator/env.lst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

RUNALL_INCLUDE ..\concepts_latest_matrix.lst
Loading