A proxy replacement for getters and setters Have you ever written proxy objects, instead of using a setter and a getter method? In that case, I'm interested in your opinion on the following design for a templated proxy:
#include &lt;type_traits&gt;
#include &lt;utility&gt;

template &lt;typename Handle, typename Getter, typename Setter&gt;
class proxy {
public:
    using value_type = decltype(std::declval&lt;Getter&gt;()(std::declval&lt;Handle&gt;()) );
    operator value_type() const { return getter_(handle_); }
    proxy&amp; operator=(const value_type&amp; x) { setter_(handle_, x); return *this; }
    proxy&amp; operator=(const value_type&amp;&amp; x) { setter_(handle_, x); return *this; }
    proxy(Handle handle, const Getter&amp; getter, const Setter&amp; setter) : 
    handle_(handle), getter_(getter), setter_(setter) { }
protected:
    const Handle handle_;
    const Getter&amp; getter_;
    const Setter&amp; setter_;
};

// Allows for template argument deduction during &quot;construction&quot; - before C++17
template &lt;typename Handle, typename Getter, typename Setter&gt;
proxy&lt;Handle, Getter, Setter&gt;
make_proxy(const Handle&amp; handle, const Getter&amp; getter, const Setter&amp; setter)
{
    return proxy&lt;Handle, Getter, Setter&gt;(handle, getter, setter);
} 

Simple example of use:
int my_getter(int *x) { return *x; }
void my_setter(int *x, int val ) { *x = val; }

class foo {
public:
    auto datum() { 
        return make_proxy(&amp;x, my_getter, my_setter);
    }
protected:
    int x { 123 };
};

int main() {
    foo my_foo;
    my_foo.datum() = 456;
    return my_foo.datum();
}

GodBolt
(in this example, the getter and setter aren't really necessary because the &quot;raw&quot; field exists. But think about opqaue operating-system resources, or individual bits in a bit-container etc.)

Other than general comments on the design - I was also thinking about the choice of template parameters. I might be able to drop the Handle type - if I could manager to extract that information from Getter; or alternatively, I could add the value_type as a template parameter - as otherwise it could be confusing to the person seeing an instantiation to understand what type they should actually use with the proxy.
Also, I was wondering whether I should provide comparators (seeing how this class is convertible to value_type's, which we should be able to compare).
Finally, I was also thinking of not keeping the getter_ and setter_ at all, and only instantiating them on use. But I'm worried this will make the class too convoluted to write and/or use.
Note: This needs to be C++11-compatible.
It's always going to be ugly
Getters and setters are never going to be as pretty in C++ as in some other languages that natively support them. Maybe something nice will be possible in a future C++ standard, but certainly not if you are stuck with C++11.
If you are going to use this to proxy member variables of a class, then the best syntax I can come up with is:
class foo {
    int x{123};
    static int getter(foo *self) { return self-&gt;x; }
    static void setter(foo *self, int val) { self-&gt;x = val; }
public:
    auto datum() { return make_proxy(this, getter, setter); }
};

The above allows the getter and setter access to the whole class, in case it wants to update multiple variables, or if the getter returns some function of multiple member variables. But unless you can reuse getters and setters, there is really not much point to it in my opinion.
The main reason is that either you have to write my_foo.datum() = 456, which has the added parentheses that make it not look like you are setting a regular member variable, or you have to declare datum like so:
class foo {
    ...
public:
    proxy&lt;foo *, decltype(getter), decltype(setter)&gt; datum{this, getter, setter};
};

That will allow you to write my_foo.datum = 456.
The former doesn't even work with C++11, since auto return type deduction doesn't work in that situation. You could add a trailing return type, but it will be ugly and repetetive. The latter has the overhead of storing three pointers for each proxy variable in your class.
It doesn't handle const instances
Your proxy class doesn't work if you create a const instance of a class that uses proxy member variables, for example:
const foo my_foo;
return my_foo.datum();

You could probably create a class const_proxy that only has a getter, and which ensures const is used in the right places, and then overload the proxy member like so:
class foo {
    ...
public:
     auto datum() { return make_proxy(this, getter, setter); }
     auto datum() const { return make_const_proxy(this, getter); }
};

But that adds even more noise.