Abusing Operator Overloading for Fun and Profit

You know there’s a good chance of a programming article being interesting/fun if it starts out like this:

“Preserve the conventional meaning of overloaded operators” — Ada Quality & Style, Overloaded Operators

Mmmmm, bite me.

And he means it! The Worried Programmer goes on to write an excellent piece on how to abusively overload operators. The article is full of great examples, like this one:

procedure Impsel is
   Which : Boolean := True;
   Letter_Choice : Natural := 2;
   Put_Line(("This here" or "That there") and Which); -- "That there"
   Put_Line(("A" or "B" or "C") and Letter_Choice);  -- "C" (0-based indexing)
   Put_Line(("A" or "B" or "C") and False);   -- Constraint_Error!
end Impsel;

Yes, really. The section of the article containing the above marvel was rightly dubbed “Losing Myself” by the author. It might not be pretty, or very Ada-like, but it sure as heck is fun!

Be sure to read the Abusing Operator Overloading for Fun and Profit article. Don’t miss out on this one!