Ioannis Vranos wrote:
>
> Yes I was talking about the flags situations, where | is used to add two
> flags (with different 1 bits) . Using the + operator makes more sense
> for me.
>
> For example (from Qt):
> model->setSorting(Qdir:
irsFirst | Qdir::IgnoreCase | QDir::Name);
>
> I think
> model->setSorting(Qdir:
irsFirst + Qdir::IgnoreCase + QDir::Name);
> is more obvious.
If you find it "more obvious" - great, use it. But you have to know what
you are doing, and keep in mind the inherent dangers of this approach.
I'd say that using '+' as an equivalent of '|' always requires an
assertion that verifies that the flags are indeed independent
STATIC_ASSERT(
(Qdir:

irsFirst & Qdir::IgnoreCase) == 0 &&
(Qdir:

irsFirst & QDir::Name) == 0 &&
(Qdir::IgnoreCase & QDir::Name) == 0);
or literally
STATIC_ASSERT(Qdir:

irsFirst + Qdir::IgnoreCase + QDir::Name ==
Qdir:

irsFirst | Qdir::IgnoreCase | QDir::Name);
(or a run-time assertion at least).
Of course, it might be sufficient to place such an assertion just once
in some place in the code, but this, in my opinion, is too high a price
to pay for your "obviousness" (which I personally don't really see).
While trying to do it without any safeguards is asking for trouble.
--
Best regards,
Andrey Tarasevich