Skip to content

Drop Init marker for rules that forward arguments - #571

Open
lucic71 wants to merge 15 commits into
Cpp2Rust:masterfrom
lucic71:init
Open

lucic71 wants to merge 15 commits into
Cpp2Rust:masterfrom
lucic71:init

Conversation

@lucic71

@lucic71 lucic71 commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

The manual Init marker on rules such as vector::emplace_back was used to encode semantic information about the rule: the forward pack is used to construct an element type.

For automatically generated rules this is not a good approach. The signature does not tell how forwarded arguments are used, this information exists as text in the description of the standard, for example:

std::map<Key,T,Compare,Allocator>::emplace

template< class... Args > std::pair<iterator, bool> emplace( Args&&... args )

Inserts a new element into the container constructed in-place with the given args, if there is no element with the key in the container. The constructor of the new element (i.e. std::pair<const Key, T>) is called with exactly the same arguments as supplied to emplace, forwarded via std::forward(args)....


This PR moves the Init marker in the Rust translation:

fn f67<T1: CppLess + Clone + ByteRepr + 'static, T2: Default + Clone + ByteRepr + 'static>(
    a0: Ptr<Map<T1, (Value<T1>, Value<T2>)>>,
    // init is the pack argument which builds typename std::map<T1, T2, T3, T4>::value_type
    // as the text of the standard says
    init: cpp_type!("typename std::map<T1, T2, T3, T4>::value_type", (Value<T1>, Value<T2>)),
) -> (Value<BidirectionalIterator<(Value<T1>, Value<T2>)>>, Value<bool>)

cpp_type has no semantic meaning for the rule, it expands to the second argument, i.e. (Value<T1>, Value<T2>).


I also added rules for std::any which builds a decay_t<T> using the forwarded arguments. I wanted to make sure that this also works.

@nunoplopes

Copy link
Copy Markdown
Contributor

(conflict)

This branch has not been deployed

No deployments
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