Mar*_*dik 0 c++ templates c++11
鉴于类型TArgument和TFunctor,我怎么能找出导致调用的一个实例的类型TFunctor与类型的参数TArgument?
这是我笨拙,肮脏的解决方案:
template <class TFunctor, typename TArgument>
class ReturnValue
{
public:
typedef decltype(functor_(arguent_)) Type;
private:
static TFunctor functor_;
static TArgument arguent_;
}
Run Code Online (Sandbox Code Playgroud)
但它的工作,既TFunctor和TArgument需要是缺省构造的.
有没有更好的办法?
typedef decltype(std::declval<TFunctor>()(std::declval<TArgument>())) Type;
Run Code Online (Sandbox Code Playgroud)
或使用std::result_of:
typedef typename std::result_of<TFunctor(TArgument)>::type Type;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
105 次 |
| 最近记录: |