on-internet
← Community

Partial class template argument deduction in C++17

Stack Overflow ·

In the example below, we use the C++17 feature "Class template argument deduction" to deduce that val is of type Base<int, double, bool>: template<class T, class U, class V> struct Base { Base(T, U) { }; Base(T, U, V) { }; Base(V) { }; }; void func() { Base val(1, 4., false); } Now, is it possible to partially specify the template arguments, and let the remaining ones be deduced? Effectively something like this: Base<V = bool> val1(1, 4.); // U & V deduced --> Base<int, double, bool> Base<T = bool, U = int> val2(5.); // V deduced, T & U given --> Base<bool, int, double> I've tried e.g. templat

Comments

Sign in or sign up to comment and upvote.

No comments yet.