If "Template type" used as function's return value, how to instantiate it without via function parameter?

My question is about "Template type" is used as return value.

Function template MakeRequest use template type as return value.
In the function template, there is a expression statement: InterfaceRequest<Interface> request;

[Q1]: How can create object "request" without function template instantiation? (MakeRequest's function parameter won't instantiate it.)

example::mojom::PingResponderRequest request = mojo::MakeRequest(&ping_responder);
[Q2]: "request" is already instantiated. the return value of "MakeRequest" is not instantiated. It's OK to assign the uninstantiated value to a instantiated value?

Thanks.
=============================
The code sample is Chromium code.
The related web address is https://cs.chromium.org/chromium/src/docs/mojo_guide.md?q=mojo_guide.md&sq=package:chromium&dr

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
template <typename Interface>
class InterfaceRequest {
...
}

template <typename Interface>
InterfaceRequest<Interface> MakeRequest(ScopedMessagePipeHandle handle) {
  InterfaceRequest<Interface> request;
  request.Bind(std::move(handle));
  return std::move(request);
}

example::mojom::PingResponderPtr ping_responder;

example::mojom::PingResponderRequest request = mojo::MakeRequest(&ping_responder);
Last edited on
1. mojo::MakeRequest<foo>(&ping_responder)
2. First of all, the term is "initialized", not "instantiated". Only types can be instantiated or not. If an object exists, it's necessarily instantiated. There's no such thing as an uninstantiated object, in the same way that there are no four-sided triangles.
Second, what do you mean? The return value of MakeRequest() is an object. After its constructor returns, an object is always initialized. For example,
1
2
3
4
std::string f(){
    std::string ret;
    return ret;
}
f() doesn't return an uninitialized object, it returns an object constructed with the default constructor.
OK, Thanks. Due to the first question, I thought "InterfaceRequest<Interface> request" is not an completed object, or a function template without instantiated.

Base on your first answer, I understood the the second question.

Besides, I mixed the two conception "initialized" and "instantiated". Thanks for your correction.
Topic archived. No new replies allowed.