Skip to content

Make generator's .end() method const#307

Merged
danvratil merged 1 commit intomainfrom
generator-end-const
Dec 10, 2025
Merged

Make generator's .end() method const#307
danvratil merged 1 commit intomainfrom
generator-end-const

Conversation

@danvratil
Copy link
Collaborator

Fixes #294.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR makes the .end() method const and constexpr for both Generator and AsyncGenerator classes, addressing issue #294. The change allows .end() to be called on const instances and enables compile-time evaluation where possible.

  • Made .end() methods constexpr and const noexcept in both generator types
  • Updated iterator constructors to support constexpr initialization
  • Changed AsyncGenerator::end() return type from auto to explicit iterator type

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
qcoro/qcorogenerator.h Made GeneratorIterator(std::nullptr_t) constructor constexpr noexcept and updated Generator::end() to be constexpr const noexcept
qcoro/qcoroasyncgenerator.h Made IteratorAwaitableBase(std::nullptr_t) constructor constexpr, changed AsyncGenerator::end() return type to explicit iterator, and made it constexpr const noexcept

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


/// Returns an iterator representing the finished generator.
auto end() noexcept {
constexpr iterator end() const noexcept {
Copy link

Copilot AI Dec 10, 2025

Choose a reason for hiding this comment

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

The end() method is marked as constexpr, but the AsyncGeneratorIterator(std::nullptr_t) constructor it calls (line 207) is not marked as constexpr. For the end() method to be properly constexpr, the constructor it invokes must also be constexpr. Consider adding constexpr to the AsyncGeneratorIterator(std::nullptr_t) constructor for consistency with the changes made to GeneratorIterator in the other file.

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@danvratil danvratil merged commit fc55c80 into main Dec 10, 2025
47 of 53 checks passed
@danvratil danvratil deleted the generator-end-const branch December 10, 2025 20:26
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.

Constness of AsyncGenerator begin and end

2 participants