Skip to content

Commit

Permalink
coro/Generator: correct Generator alias of std::generator (#385)
Browse files Browse the repository at this point in the history
* coro/Generator: correct Generator alias of std::generator

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]>

* coro/Generator: use <generator> only if __cpp_lib_generator

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]>

---------

Signed-off-by: Kefu Chai <[email protected]>
  • Loading branch information
tchaikov authored Jul 24, 2024
1 parent 6ee73d3 commit 7cdb214
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions async_simple/coro/Generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
#warning "Clang 15 is not supported for Generator due to some issues."
#endif

#if __has_include(<generator>)
#if defined(__cpp_lib_generator) && __has_include(<generator>)

#include <generator>

namespace async_simple::coro {

template <class Ref, class V = void, class Allocator = void>
using Generator = std::generator<Ref, V, AlloAllocator>;
using Generator = std::generator<Ref, V, Allocator>;

} // namespace async_simple::coro

Expand Down

0 comments on commit 7cdb214

Please sign in to comment.