Ecco cosa voglio fare:Un modo migliore per disabilitare la deduzione dei parametri del template basata su argomenti per le funzioni?
template <typename T> void f(DisableDeduction<T> obj) {std::cout << obj;}
// Here DisableDeduction<T> aliases T, but in a such way
// that would prevent compiler from deducing T based
// on provided argument.
/* ... */
f<int>(1); // Works.
f(1); // Error, can't deduce template parameter based on argument.
Ecco come ho attualmente realizzarlo:
template <typename T> struct DisableDeduction_Internal {using type = T;};
template <typename T> using DisableDeduction = typename DisableDeduction_Internal<T>::type;
Funziona perfettamente (come descritto), ma introduce un tipo di supporto aggiuntivo.
Ma posso ottenere lo stesso risultato senza tipi aggiuntivi?
'std :: enable_if_t'? –
Jarod42
@ Jarod42, ti dispiacerebbe trasformarlo in una risposta con un esempio funzionante? –