Okay, I\'ve been inspired to do some head punching. Seems like overloading operator&
leads to not a small amount of pain.
What legitimate cases exis
Four years later, another answer.
Another use I have seen is when you are piggybacking off of the C++ language, but defining your own semantics. Prime example: Boost.Spirit.
Boost.Spirit, in particular Qi for parsing, overloads operators on parsers to provide an EBNF-like syntax for specifying arbitrary parser objects. In particular, the unary &
operator is overloaded to provide the And-Predicate Parser.
And-Predicate Parser (&a)
Description
Syntactic predicates assert a certain conditional syntax to be satisfied before evaluating another production. Similar to semantic predicates, eps, syntactic predicates do not consume any input. The and-predicate, &a, is a positive syntactic predicate that returns a zero length match only if its predicate matches.
Example usage:
Basic look-ahead example: make sure that the last character is a semicolon, but don't consume it, just peek at the next character:
test_phrase_parser("Hello ;", lit("Hello") >> &lit(';'), false);
So in short, the unary &
here has no relation to pointers at all; it has domain-specific semantics which apply to Qi parser objects.