[Interest] QDatastream, QMap, QImage serialization

Jason H jhihn at gmx.com
Mon May 21 20:50:02 CEST 2018


>
> On Monday, 21 May 2018 13:04:00 -03 Jason H wrote:
> > which makes me think it should be T texture<T>();
> 
> THAT is not going to happen.
> 
> Find a non-template name and we can talk.

I don't think C++ has a good concept of what it is that I want to do. C++ does not allow multiple return types from functions, therefore, the only way to get the type you want returned is provide an overload with different parameters.  What is needed is something "orthogonal" to an enum. Whereas enums are all the same type, you need a thing that is the same "thing" but different type. You can't use enums names because it's too easy to convert between them since they are all ints under the hood. 

class QPixmapAtom {};
class QImageAtom {};
class QBrush {
...
    QPixmap texture(QPixmapAtom());
    QImage texture(QImageAtom());
};

However this idea of class atoms I think is completely foreign to C++. It also allows for inheritance where something can inherit QImageAtom (which enums can't do (I don' think...)) providing more specialization of the atom.  (A molecule?) (You can call it a "hint" as well though existing "hints" in Qt are enums, so I'm trying to stay away from that.)

What I like about it is I don't have to remember if texture() returns a pixmap or an image. It'll return a type matching whatever "atom" I gave it. 




More information about the Interest mailing list