Last active
December 15, 2015 20:18
-
-
Save nurettin/5317085 to your computer and use it in GitHub Desktop.
C#? in my C++11 ?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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