samedi 12 novembre 2016

How to impose a lexicographic order on an (arbitrary) POD C++ struct?

I have some POD struct foo; suppose it's struct foo { int x; unsigned y; }. I want to be able to compare struct foo's using lexicographic order - by order of their fields of course. That is, I want all of the operators <, ==, >, etc. to work for struct foo's

Can I do this in some generic way, without having decorated my structure definition with any reflection voodoo - and without just spelling out all those operator definitions? Or is the ability to do this too much of a "language reflection dependent" expectation?





Aucun commentaire:

Enregistrer un commentaire