Skip to content

Use C++20 iterator concepts in our format headers - #497

Merged
Neverlord merged 1 commit into
masterfrom
topic/neverlord/use-iterator-concepts
Jan 21, 2026
Merged

Neverlord merged 1 commit into
masterfrom
topic/neverlord/use-iterator-concepts

Conversation

@Neverlord

Copy link
Copy Markdown
Member

Modernize our format headers with more C++20 concepts.

Copilot AI left a comment

Copy link
Copy Markdown

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 modernizes the format headers in libbroker by replacing traditional template metaprogramming patterns with C++20 concepts, improving code clarity and type safety. The changes introduce custom iterator concepts and leverage standard library concepts for more expressive template constraints.

  • Introduces three new concepts in type_traits.hh: byte_output_iterator, char_output_iterator, and arithmetic
  • Replaces class OutIter template parameters with concept-constrained parameters across all format headers
  • Converts requires clauses and SFINAE patterns to more concise concept-based constraints (e.g., std::same_as<data>, std::integral)
  • Updates iterator template parameters from generic names to standard concepts (std::input_iterator, std::sentinel_for)

Reviewed changes

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

File Description
libbroker/broker/detail/type_traits.hh Adds forward declaration for caf::byte and defines three new concepts for output iterators and arithmetic types
libbroker/broker/format/txt.hh Replaces unconstrained template parameters with detail::char_output_iterator, std::integral, and std::same_as concepts; adds <concepts> and <iterator> includes
libbroker/broker/format/json.hh Applies similar concept constraints for output iterators and integral types; adds explicit include of type_traits.hh; changes iterator parameter names from ForwardIterator to Iterator with std::input_iterator concept
libbroker/broker/format/bin.hh Replaces template constraints with detail::byte_output_iterator, std::unsigned_integral, std::same_as, and detail::arithmetic concepts; removes unused <vector> include

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

@Neverlord
Neverlord marked this pull request as ready for review December 14, 2025 09:12
@Neverlord
Neverlord merged commit 5fe94bb into master Jan 21, 2026
24 checks passed
@Neverlord
Neverlord deleted the topic/neverlord/use-iterator-concepts branch January 21, 2026 08:03
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.

3 participants