Sometimes, we need to create wrapper types.
optional and similar.
these types have an accessor member function called
but they also provide the
operator-> to support
direct access to the contained value
similarly to what ordinary pointers do.
The problem is that sometimes we have a few of these types
nested into each other.
This means that we need to call
.get multiple times,
or to have a lot of dereference operators
until we reach the value.
Something like this:
This can be a bit ugly.
If we can replace one
.get() with an arrow,
it would be nice if we could replace the second
.get() as well.
For this, the C++98 introduced a long arrow operator.
What if we have another layer of wrapping? Just make a longer arrow.
With a special implementation of
this compiles and works without many problems.
Now, before we continue,
you should realize that this post is not a serious one.
And that this should never be used in a serious project,
just like the left arrow operator
and the WTF operator
??!??!  (which no longer works in C++17 BTW).
Like in the
the long arrow is not a single operator,
but a combination of multiple operators.
In this case,
-> operator and the postfix decrement operator
So, when we write
the compiler sees
If we define the postfix
-- to be the same as the dereference operator,
we get the long arrow, and the even longer arrow operators: