[Development] char8_t summary?

Matthew Woehlke mwoehlke.floss at gmail.com
Mon Jul 15 18:41:24 CEST 2019


On 14/07/2019 02.28, Mutz, Marc via Development wrote:
> If you're still not convinced, here's QStringView::endsWith() as a
> template:
> 
>    template <typename Prefix>
>        requires std::is_convertible_v<Prefix, QStringView // || ...
> Qtf8StringView, || ... QLatin1StringView  ...
>    Q_ALWAYS_INLINE
>    bool endsWith(Prefix &p) const {
>        return QtPrivate::endsWith(*this,
> QtPrivate::qStringLikeToStringView(p));
>    }
> 
> with a qStringLikeToStringView() similar to the one in 181620. This uses
> C++20, and I'm sure it loses something over the current implementation.
> Qt::CaseSensitivity comes to mind.

...and I don't know why you didn't just propagate through the case
sensitivity argument?

> To anyone speaking up in favour of
> the box: Please write this in C++11 before you hit reply :)

IIUC, replacing the `requires` is trivial. A bit ugly, sure, but not
difficult.

I also question the value of the indirection in the above. Moving the
implementation of QtPrivate::endsWith to be inline, and making use of
`if constexpr` where useful, will hopefully reduce the total amount of
code. (Yes, eventually you're going to have an optimized string
comparison. Helper code like that to implement the critical code paths
will still exist, but hopefully those are bits that get used over and
over in many methods.)

Note also that I suggested having the template definition out-of-line;
it doesn't need to be in (e.g.) qstring.h or anywhere that will affect
*user* compile times. Only the TU responsible for instantiating them
would be affected, and that should be negligible in the grand scheme of
things.

BTW, I don't think ternary functions are an issue. The ones that come to
mind will "always"¹ need to convert one of their arguments anyway, so
while the *templates* may involve another level of combinatorics, that
level won't affect the implementation complexity in any meaningful way.

(¹ Possibly they can skip this because that argument is never actually
used, but otherwise it must be converted.)

-- 
Matthew


More information about the Development mailing list