Skip to content

how should function templates with explicit template arguments be exposed by C++ interop? #6768

@zygoloid

Description

@zygoloid

Summary of issue:

Example: std::make_unique expects to be passed a type as an explicit template parameter. We probably want a call such as Cpp.std.make_unique(MyType, arg1, arg2) to construct it from arg1, arg2. If so, how do we achieve that?

Details:

Probably the most obvious approach would be to say: if a template parameter is not deducible, then it must be explicitly specified in a call. That works for make_unique, and probably works fairly well in general, except for two things:

  1. make_unique is overloaded. How should we handle the case where different overloads have different sets of non-deducible template parameters? Perhaps we could just reject such a call and ask for some explicit syntax to be used to indicate what the template arguments are.
  2. While this may be a good default, it doesn't allow us to perform any call that's possible in C++, and doesn't give a way to override the default. One example where this comes up in practice in C++ is calls to std::min, where a deduced template argument is often fine, but sometimes you would want to call (eg) std::min<int64_t> because deduction would otherwise fail or pick the wrong type.

So perhaps we should additionally have some mechanism to explicitly specify the template arguments. If it's rarely used, I suppose it might be OK for it to be a little verbose. For example, we could use something like:

Cpp.std.min(Cpp.template(i32), 1, 2)

(where Cpp.template wraps a tuple of arguments so that the C++ call machinery knows to treat them as template arguments).

Any other information that you want to share?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    examples-2026An issue that is relevant for examples we are trying to port to Carbon in 2026.leads questionA question for the leads team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions