I've recently come across the need to apply a pointer-to-member to the object designated by an iterator. I've tried the natural syntax :
ite->*ptr = 42;
To my dismay, it didn't compile. Iterators don't overload operator->*
, but more surprisingly neither do smart pointers. I needed to resort to the following clunkiness :
(*ite).*ptr = 42;
Experimenting (see the live example below) has shown that such a syntax seems to be achievable for custom classes, for both pointers-to-members and pointers-to-member-functions, at least since C++14.
Thus :
- Is there a reason the standard pointer-like classes don't overload
operator->*
, or is it just an oversight ? - Should I overload
operator->*
when defining my own pointer-like classes, or does this same reason apply to me ?
Live example -- what compiles, what doesn't, and a proof-of-concept for a custom class.