[ create a new paste ] login | about

Link: http://codepad.org/0F9Dls8G    [ raw code | fork ]

Niels - C++, pasted on Dec 25:
// C++ code from Johannes Schaub (litb)    
// C++0x: Is this "this-parameter" forwarder for function<void(???)> correct?
// http://groups.google.com/group/comp.lang.c++/msg/9a6c60fdb70d638c
// Tested by doing g++ -std=c++0x on GCC 4.5.1 20100924 (Red Hat 4.6.1-4)
//
#include <functional>
using std::placeholders::_1;
using std::bind;
using std::function;

struct Class { void f() { } };


template<typename T> struct ThisParam {
  T *t;
  ThisParam(T *t):t(t) { }
  ThisParam(T &t):t(&t) { }

  operator T*() const { return t; }
  operator T&() const { return *t; }

};

int main()
{
  function<void(ThisParam<Class>)> f = bind(&Class::f, _1);
  Class a;
  f(a);
  f(&a);
}


Create a new paste based on this one


Comments: