
Stewart, Robert wrote: [snip]
To avoid the precedence problem, the available operators that make any sense at all are:
convert(s)[5] >> std::hex; convert(s) ! 5 >> std::hex; convert(s) ~ 5 >> std::hex; convert(s) & 5 >> std::hex; convert(s) / 5 >> std::hex; convert(s) % 5 >> std::hex;
The subscript operator is not bad. "[5]" implies that 5 is optional in a number of contexts. Bang suggests using 5 on error. Tilde doesn't evoke "default" in any way, but it also doesn't look like an egregious misuse of the operator. The final three just look wrong to me.
Given that the default value calls should be easy to get right and that the precedence issue will bite many, we should select a different operator if we choose to retain an operator for the job. Among the available choices, I favor bang:
convert(s) ! 5 >> std::hex;
How is that? Both ! and ~ were unary operators last time I checked :) Best Regards, Gevorg