Skip to content

type: Accept any comparator, hash, and allocator in container fields - #379

Open
ryanofsky wants to merge 1 commit into
bitcoin-core:masterfrom
ryanofsky:pr/containers
Open

ryanofsky wants to merge 1 commit into
bitcoin-core:masterfrom
ryanofsky:pr/containers

Conversation

@ryanofsky

Copy link
Copy Markdown
Collaborator

Problem: std::vector, std::set, std::map and std::unordered_set fields and parameters only work when they use the default comparator, hash and allocator types. Anything else, like Bitcoin Core's GCSFilter::ElementSet (std::unordered_set<Element, ByteVectorHash>), fails to compile with "no matching function for call to CustomBuildField". Bitcoin Core currently works around this by copying the std::unordered_set read and build functions into its own code (bitcoin/bitcoin#29409).

Solution: Make the container overloads in type-vector.h, type-set.h, type-map.h and type-unordered-set.h templates over the containers' comparator, hash and allocator types. Small change to the four headers, plus a FooStruct round-trip test with a descending std::set and std::map, an std::unordered_set with a custom hash, and a std::pmr::vector.

Let std::vector, std::set, std::map, and std::unordered_set fields use any
comparator, hash, or allocator type, instead of only matching containers
with the default template arguments. Previously, a field like Bitcoin Core's
GCSFilter::ElementSet (std::unordered_set<Element, ByteVectorHash>) didn't
match any overload, so Bitcoin Core had to copy the std::unordered_set read
and build functions to pass it over IPC.

This change was written with Claude Opus 5.5 (1M context).
@DrahtBot

DrahtBot commented Oct 15, 2026 •

Copy link
Copy Markdown

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Reviews

See the guideline and AI policy for information on the review process.
A summary of reviews will appear here.

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