Jakob Ƙstergaard Hegelund

Tech stuff of all kinds

Pick the pointer

2014-04-11

This is probably not the best way to go about things, from a readability perspective... But it just occurred to me today that there's yet another use for std::max. Consider:

    fsal::Entity *se = ptrl
      ? static_cast<fsal::Entity*>(ptrl.ptr())
      : static_cast<fsal::Entity*>(ptrc.ptr());
Since ptrl.ptr() and ptrc.ptr() are diffferent types, I need to cast them both separately. This is a lot of typing and a lot of reading. The shorter way? How about:
    fsal::Entity *se = std::max<fsal::Entity*>(ptrl.ptr(), ptrc.ptr());
I will make the argument that this is elegant. It is short and concise and does exactly what I need (it picks out the one pointer that is not 0). As for readability, this is so far from "normal" that it is probably not a good idea.