[Development] QDataStream: blackbox or document all versions?

Marc Mutz marc.mutz at kdab.com
Mon Sep 26 10:24:21 CEST 2016


On Monday 26 September 2016 10:11:09 Ulf Hermann wrote:
> This doesn't change the implicit conversion problem that Marc mentioned,
> but at the moment I don't quite see a way to fix it without removing a lot
> of convenience for the user (that is, have the user specify the exact
> intended type for each serialization operation).

The solution is to have just one (templated) op<</op>> and (partially) 
specialise a struct that contains a static function (or a function call 
operator). This is how std::hash works (except it lacks the convenience 
function so you have to be explicit about the type), and why it's not 
susceptible to problems such a qHash(badly-designed smart-pointer) invoking 
qHash(bool) (if we had qHash(bool), which we don't have, for precisely that 
reason).

Another solution is to write every op<</op>> as a constrained template, but 
that is decidedly not user-friendly (where user here is the user that extends 
op<</>> to her own types).

Thanks,
Marc

-- 
Marc Mutz <marc.mutz at kdab.com> | Senior Software Engineer
KDAB (Deutschland) GmbH & Co.KG, a KDAB Group Company
Tel: +49-30-521325470
KDAB - Qt, C++ and OpenGL Experts



More information about the Development mailing list