You want to deduce the template parameters of WWWWWW based on the type of result that is passed to AEWQWQWQW. You can achieve this using C++20's template argument deduction for class templates, but since AAA is a template and not a type, you need to use decltype to get its type and then extract its template parameters.
Here's a possible solution:
if (cond) {
AEWQWQWQW(req, result);
} else {
WWWWWW<CommonResultType, sizeP>(req); // if you know CommonResultType and sizeP
// or
WWWWWW<std::decay_t<decltype(result)>::template_type::CommonResultType,
std::decay_t<decltype(result)>::sizeP>(req); // if you know the internals of AAA
// or more likely
WWWWWW<typename std::decay_t<decltype(result)>::value_type,
std::decay_t<decltype(result)>::sizeP>(req); // a more typical pattern
}
However, the above code assumes knowledge of the internals of AAA. A more general and flexible solution is to create a type trait to extract the template parameters from AAA:
template <typename T>
struct extract_AAA_params;
template <template <typename, size_t> typename AAA_T, typename CommonResultType, size_t sizeP>
struct extract_AAA_params<AAA_T<CommonResultType, sizeP>> {
using type = CommonResultType;
static constexpr size_t size = sizeP;
};
// usage
if (cond) {
AEWQWQWQW(req, result);
} else {
using result_type = std::decay_t<decltype(result)>;
WWWWWW<typename extract_AAA_params<result_type>::type,
extract_AAA_params<result_type>::size>(req);
}
However, if you are using C++20, a more elegant solution is to use CTAD (Class Template Argument Deduction) and a deduction guide for WWWWWW, or simply define WWWWWW in a way that it can deduce its template parameters from its arguments.
template <typename CommonResultType, size_t sizeP>
void WWWWWW(const ZZZ<sizeP>& request, [[maybe_unused]] AAA<CommonResultType, sizeP> dummy = {}) {
// implementation
}
// usage
if (cond) {
AEWQWQWQW(req, result);
} else {
WWWWWW(req, result); // or WWWWWW(req);
}
In this case, you don't need to explicitly specify the template parameters for WWWWWW. The compiler will deduce them based on the type of result.
If you can't change the signature of WWWWWW, you can create a helper function that can deduce the template parameters and then call WWWWWW:
template <typename CommonResultType, size_t sizeP>
void WWWWWW_helper(const ZZZ<sizeP>& request, const AAA<CommonResultType, sizeP>&) {
WWWWWW<CommonResultType, sizeP>(request);
}
// usage
if (cond) {
AEWQWQWQW(req, result);
} else {
WWWWWW_helper(req, result);
}