在Boost Signals库中,它们重载了()运算符.
这是C++中的约定吗?对于回调等?
我在同事的代码中看到了这一点(恰好是Boost的忠实粉丝).在那里的所有Boost善良中,这只会让我感到困惑.
有关这种超载原因的任何见解?
c++ boost operator-overloading functor function-call-operator
是否可以编写一个C++(0x)元函数来确定一个类型是否可调用?
通过可调用类型我的意思是函数类型,函数指针类型,函数引用类型(这些被检测到boost::function_types::is_callable_builtin),lambda类型,以及任何具有重载的类operator()(也许任何类具有隐式转换运算符到其中一个,但这不是绝对有必要).
编辑:元函数应检测operator()任何签名的存在,包括模板化operator().我相信这是困难的部分.
编辑:这是一个用例:
template <typename Predicate1, typename Predicate2>
struct and_predicate
{
template <typename ArgT>
bool operator()(const ArgT& arg)
{
return predicate1(arg) && predicate2(arg);
}
Predicate1 predicate1;
Predicate2 predicate2;
};
template <typename Predicate1, typename Predicate2>
enable_if<ice_and<is_callable<Predicate1>::value,
is_callable<Predicate2>::value>::value,
and_predicate<Predicate1, Predicate2>>::type
operator&&(Predicate1 predicate1, Predicate2 predicate2)
{
return and_predicate<Predicate1, Predicate2>{predicate1, predicate2};
}
Run Code Online (Sandbox Code Playgroud)
is_callable 是我想要实现的.