Created
April 5, 2013 06:56
-
-
Save nurettin/5317182 to your computer and use it in GitHub Desktop.
in my c++?!
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); } | |
}; | |
struct Wtf | |
{ | |
Property<int> TheInt; | |
Property<double> TheDouble; | |
Wtf() | |
: TheInt{ 0, | |
[&](){ return TheInt.value; }, | |
[&](int x){ TheInt.value= x; } | |
} | |
, TheDouble{ 0, | |
[&](){ return TheDouble.value; }, | |
[&](double x){ TheDouble.value= x; } | |
} | |
{} | |
}; | |
#include <iostream> | |
int main() | |
{ | |
Wtf lol; | |
lol.TheInt= 42; | |
lol.TheDouble= 3.141592; | |
std::cout<< lol.TheInt<< " "<< lol.TheDouble; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment