}
template <typename AAA, size_t sizeP>
void xxxxQQQQ(const Request<sizeP>& request,
Response<AAA, sizeP>&) {
}
template<typename T>
using Response = vector<Wrapper<T>>
Response... response
why vvvvWWWW<decltype(response)::value_type>(request) is not same like xxxxQQQQ(request, response) but both are compiling ?
CAN WE DO SOMETHIGN LIKE THIS IN C++20?
template <typename class<typename AAA, size_t> Proxy, size_t sizeP>
void vvvvWWWW(const Request<sizeP>& request) {
NOTE! typename AAA is not ::value_type and I have not code for accessing
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Short answer – vvvvWWWW can’t deduce the first template parameter (AAA) from its argument list, while xxxxQQQQ can.
C++ does not “look inside” the explicit call vvvvWWWW< … >( … ) and see that the two names are “morally the same”; it simply applies the normal template-argument-deduction rules to each function separately.
• In (1) the parameter AAA does not appear in any of the
function-parameter types.
→ The compiler therefore cannot deduce it and the caller must supply it
explicitly:
cpp
vvvvWWWW<SomeType>(req); // OK (AAA = SomeType, N deduced)
vvvvWWWW(req); // ❌ AAA can’t be deduced
• In (2) the second function parameter is Response<AAA , N>&.
→ Both AAA and N appear in that type, so they can be deduced:
cpp
xxxxQQQQ(req , resp); // OK (AAA & N both deduced)
Your hand-written call
cpp
vvvvWWWW<decltype(resp)::value_type>(req);
works because you manually told the compiler what AAA is; N
is still deduced from the Request<N> argument.
Making vvvvWWWW work “like” xxxxQQQQ
The function must receive (directly or indirectly) something that
mentions AAA, otherwise deduction is impossible.
Two typical solutions:
You can then call the function with any class-template (or C++20 alias-template) that matches the signature:
cpp
template<typename T , std::size_t N>
using Response = std::vector<Wrapper<T>>; // alias template (two params)
Request<10> req;
Response<int , 10> resp;
vvvvWWWW<Response>(req , resp); // OK
Notes:
• The alias template Response must indeed take two template
parameters if you want to write Response<AAA , sizeP>.
• Since C++20, alias templates are allowed as template-template arguments
as long as their parameter lists are compatible (P0522).
Key take-aways
• A template parameter can only be deduced if it appears (unambiguously)
in one of the function-parameter types.
• If deduction is impossible, you must write the argument explicitly.
• To pass “a family of templates” (e.g. Response<…>), use a
template-template parameter:
template< template<typename, std::size_t> class Proxy, … >
• Alias templates (using Foo = …) can be used as template-template
arguments in C++20 provided they match the required arity.
That explains why the two calls compile, why they are not “the same” for
the compiler, and how to express the idea cleanly in modern C++.