Left Arrow Operator

Kent - January 13, 2024

Usually the right arrow operator -> will point to some method or value of a pointer. There is also a left arrow operator <-, it is used when you have a pointer to a method and it should be invoked on a class.

https://www.atnnn.com/p/operator-larrow/

Use this if you are brave.

#include <iostream>
 
template<class T>
struct larrow {
    larrow(T* a_) : a(a_) { }
    T* a;
};
 
template <class T, class R>
R operator<(R (T::* f)(), larrow<T> it) {
    return (it.a->*f)();
}
 
template<class T>
larrow<T> operator-(T& a) {
    return larrow<T>(&a);
}
 
struct C {
    void f() { std::cout << "foo\n"; }    
};
 
int main() {
    C x;
    (&C::f)<-x;
}

See Also

Comments

Any comments? Create a new discussion on GitHub.
There used to be an inline comment form here, but it was removed.