问题描述
我想在gtk ++的goocanvas中使用lambda表达式。就我的理解而言,这意味着我必须能够将lambda放入sigc ++仿函数中。
I want to use lambda expressions in connection with goocanvas in gtk++. For my understanding this means that I must be able to put my lambda in a sigc++ functor.
我尝试过类似的操作:
sigc::slot<bool, const Glib::RefPtr<Goocanvas::Item>& , GdkEventMotion* > slot2=
[]( const Glib::RefPtr<Goocanvas::Item>& item, GdkEventMotion* ev)->bool
{
cout << "Lambda " << endl; return false;
};
((Glib::RefPtr<Goocanvas::Item>&)item1)->signal_motion_notify_event().connect( slot2);
但这不会编译。
我有机会在没有sigc ++中间体的情况下直接与lambdas或更好的gtkmm一起使用sigc:-)
Is there a chance to get sigc working with lambdas or better gtkmm directly without the sigc++ intermediate :-)
推荐答案
我发现了以下内容代码被截断以完成工作。我不知道它如何与sigc ++ lib交互,但是我可以在简单的情况下使用它。也许其他人可以看一下。
I found the following code snipped which do the job. I have no idea how this interacts with the sigc++ lib, but I can use it for simple cases. Maybe someone else can take a look on it.
#include <type_traits>
#include <sigc++/sigc++.h>
namespace sigc
{
template <typename Functor>
struct functor_trait<Functor, false>
{
typedef decltype (::sigc::mem_fun (std::declval<Functor&> (),
&Functor::operator())) _intermediate;
typedef typename _intermediate::result_type result_type;
typedef Functor functor_type;
};
}
更新:
Libsigc现在无需任何其他即可处理lambas用户代码。如果使用任何当前版本,则必须删除上述代码。
UPDATE:Libsigc is now able to handle lambas without any additional user code. The above code must be removed if any current versions is used.
这篇关于在sigc库中使用lambda的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!