C ++ 11查找类型是否具有成员函数或支持运算符的方法? [英] C++11 ways of finding if a type has member function or supports operator?

查看:88
本文介绍了C ++ 11查找类型是否具有成员函数或支持运算符的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一种(似乎)好的C ++ 03方法来查找类型是否具有成员函数或运算符:

There is a (seemingly) nice C++03 way of finding out if a type has a member function or operator:

https://github.com/jaredhoberock/is_call_possible/blob/master/is_call_possible.hpp

有没有现代的C ++ 11方法来做到这一点?最好不要包含任何外部代码,只使用标准。

Is there no modern C++11 way to do this? It would be better not having to include any external code and use only the standard.

推荐答案

不,它几乎是一样的。或多或少。实现方式各不相同,但您可以使用标准库特性来替换该实现内部使用的一些元函数。但是没有检测是否可以通过给定一些参数来调用某个类型的函数的方法。

No, it's pretty much the same way. More or less. Implementations vary, though you could replace some of the metafunctions used internally by that implementation with standard library traits. But there's no simple way of detecting if you can invoke a function on some type given some set of arguments.

这是概念(PDF)

这篇关于C ++ 11查找类型是否具有成员函数或支持运算符的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆