Challenge: adding new method overloads when existing consumers use {} with args
Thiago Macieira
thiago at kde.org
Thu Jul 28 00:38:50 BST 2022
On Wednesday, 27 July 2022 14:37:20 PDT Friedrich W. H. Kossebau wrote:
> * new overload method (and any further ones) will stay special
> * existing consumer code using {} is not that simple to map by human readers
> as to which overload will be used
> * needs C++17, so needs some additional markup when used in KF5 headers for
> those using them with C++11-compat needs
You can use std::enable_if (no _t).
Another trick is what we do in Qt with Q_WEAK_OVERLOAD:
template <typename = void>
It doesn't matter what the parameters are and that this new template function
doesn't actually use the template parameter. As a template function, it will
not get selected for conversion; the types must match exactly.
This is handy even without {}, when you want to down-prioritise some overloads
over others for some reason, to avoid ambiguity. For example, you can't
overload a QByteArray with QLatin1String (or Qt6's QByteArrayView or
QAnyStringView or any such other combination) because it makes calling with a
character literal ambiguous. But you can if one of them is a weak overload.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel DPG Cloud Engineering
More information about the kde-devel
mailing list