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

coro/Generator: correct Generator alias of std::generator #385

Merged
merged 2 commits into from
Jul 24, 2024

Conversation

tchaikov
Copy link
Contributor

before this change, the build fails, because AlloAllocator is not defined when the standard library provides std::generator, and the tree is built with C++23.

in this change, we replace AlloAllocator with Allocator. and the tree builds fine.

also, we include <generator> only if __cpp_lib_generator is defined. as the existence of the header does not imply that we are building with C++23.

tchaikov added 2 commits July 24, 2024 09:13
before this change, the build fails, because `AlloAllocator` is
not defined when the standard library provides `std::generator`,
and the tree is built with C++23.

in this change, we replace `AlloAllocator` with `Allocator`. and
the tree builds fine.

Signed-off-by: Kefu Chai <[email protected]>
std::generator is a feature provided by C++23, when the tree is built
with C++20, even if `<generator>` header is available, we still don't
have access to `std::generator`. and the compiler would fail to compile:

```
In file included from /home/kefu/dev/async_simple/async_simple/coro/test/GeneratorTest.cpp:29:
/home/kefu/dev/async_simple/async_simple/coro/Generator.h:32:24: error: no template named 'generator' in namespace 'std'; did you mean 'generate'?
   32 | using Generator = std::generator<Ref, V, Allocator>;
      |                   ~~~~~^~~~~~~~~
      |                        generate
/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/stl_algo.h:4344:5: note: 'generate' declared here
 4344 |     generate(_ForwardIterator __first, _ForwardIterator __last,
      |     ^
In file included from /home/kefu/dev/async_simple/async_simple/coro/test/GeneratorTest.cpp:29:
/home/kefu/dev/async_simple/async_simple/coro/Generator.h:32:19: error: expected a type
   32 | using Generator = std::generator<Ref, V, Allocator>;
      |                   ^
/home/kefu/dev/async_simple/async_simple/coro/Generator.h:32:24: error: expected ';' after alias declaration
   32 | using Generator = std::generator<Ref, V, Allocator>;
      |                        ^
      |                        ;
```

in this change, we guard the include with `__cpp_lib_generator`,
to address the FTBFS.

Signed-off-by: Kefu Chai <[email protected]>
Copy link
Collaborator

@ChuanqiXu9 ChuanqiXu9 left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks.

@ChuanqiXu9 ChuanqiXu9 merged commit 7cdb214 into alibaba:main Jul 24, 2024
14 checks passed
@tchaikov tchaikov deleted the generator branch July 24, 2024 02:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants