[sigc] Functor from variable



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello,

I was just wondering if it is possible in libsigc++ to create a functor
from a variable. So you get a functor that returns the value of this
variable and receives no parameter.

I've seen there's a way to get a similar effect by binding the return of
a function of the same type to a sigc::ref of the variable. Something
like this:

- -- Example --
int dummyOne()
{
~  cout << "Calling " << __FUNCTION__ << endl;
~  return 0;
}

int main(int argc, char* argv[])
{
~  int data;
~  sigc::signal<int> readValue;

~  readValue.connect(sigc::bind_return(&dummyOne, sigc::ref(data)));

~  data = 3;
~  cout << readValue() << endl;

~  data = 5;
~  cout << readValue() << endl;
}
- -- End of Example --

- -- Output --
Calling dummyOne
3
Calling dummyOne
5
- -- End of Output --

Is there a way to avoid the unnecessary call to dummyOne? Maybe making
inline the dummy function would reduce it (already small) impact?

Something like

~  readValue.connect(sigc::var_fun(sigc::ref(data)));

sigc::var_fun would create a functor that returns the type of data (int)
and receives no parameter (a 0-ary function).

Thank you for your attention!

- --
Roger Ferrer Ibáñez
Correu: rofi ya com
Correu (FIB): b4270692 est fib upc es
Correu (Casa): roger pinchito com
Correu (JEDI): rogerf jedi upc es
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFBEn53s5A+cAGo9FoRAvlJAJ4ngzoAutU1OQD5nryIHpfSOIX26QCfQLnN
4NvRTIaHMJHz2kBgtoK+56o=
=gkpv
-----END PGP SIGNATURE-----



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]