1

Suppose there is a class with two template parameters

template<typename A, typename B>
class C {
  C(B::X x) {}
};

is it possible to have a deduction guide where only one of the parameters is inferred and the other is user-specified?

template<typename A, typename D>
C(D) -> C<A, D::Y>;

When I try this, clang gives me "deduction guide template contains a template parameter that cannot be deduced"

user835943
  • 171
  • 9
  • The simple answer is no. – 康桓瑋 Nov 11 '21 at 12:58
  • The longer answer is that CTAD is explicitly disabled the moment you add template arguments. `C c(whatever);` **will not** do CTAD. If you don't have a viable default argument, you are out of luck. Your problem is solved with a factory function, something like the `make_*` functions in the standard library. – StoryTeller - Unslander Monica Nov 11 '21 at 13:09

0 Answers0