Skip to content

Instantly share code, notes, and snippets.

@nurettin
Last active December 15, 2015 20:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nurettin/5317085 to your computer and use it in GitHub Desktop.
Save nurettin/5317085 to your computer and use it in GitHub Desktop.
C#? in my C++11 ?
#include <functional>
template <typename T>
struct Property
{
T value;
std::function<T()> getter;
std::function<void(T)> setter;
operator T(){ return getter(); }
void operator= (T wtf){ setter(wtf); }
};
#include <iostream>
int main()
{
Property<int> lol {0, [&](){ return lol.value; }, [&](int x){ lol.value= x; } };
lol= 42;
Property<int> omg {0, [&](){ return omg.value; }, [&](int x){ omg.value= x; } };
omg= 1337;
std::cout<< lol<< '\n'<< omg;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment