Skip to content

Instantly share code, notes, and snippets.

@nurettin
Created April 5, 2013 06:56
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/5317182 to your computer and use it in GitHub Desktop.
Save nurettin/5317182 to your computer and use it in GitHub Desktop.
in my c++?!
#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