0

I have some code like this

template<A, B, C, D, E>    
return_type f(param1_type p1, shared_ptr<B>, E)
{
   // param1_type A B C D E used here

   // returns type return_type
}

where return_type and param1 are known types (not templates).

All calls to this function will use an function specialization that I have created. So I know what types A C D should be when B and E are passed.

I'm trying to add deduction guides to avoid passing any templates to this function.

The code I tried was

return_type f(param1_type, shared_ptr<param2_type>, param3_type) -> return_type <param2_type, SomeClass1, SomeClass2, SomeClass3, param3_type>f(param1_type, shared_ptr<param2_type>, param3_type);

Although this deduction guide doesn't seem to work.

error: expected function body after function declarator

What's wrong with my syntax?

Cedric Martens
  • 1,139
  • 10
  • 23
  • 1
    Function templates don't have deduction guides. – Jason Jun 16 '22 at 16:39
  • You don't need deduction guides for function templates either. From your question is is not clear to me what specifically you are trying to do here, but you can always just implement a function template directly or with the help of some forwarding overloads to have the effect you seem to be looking for. – user17732522 Jun 16 '22 at 16:47
  • "_So I know what types A C D should be when B and E are passed._": Then you don't need to have `A`, `C` and `D` be template parameters. They can be chosen inside the function with alias declarations, e.g. `using A = std::conditional_t, float, double>;` or, depending on intended use, you might be looking for _explicit specialization_ of the function template or something like a traits class that can be partially/explicitly specialized to provide mapping of the types. – user17732522 Jun 16 '22 at 16:49

0 Answers0