- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直在为最近发布的一些问题寻找一些解决方案,这些问题的原始发问者一直在尝试查询给定类中是否存在某个方法。我一直在尝试使用 SFINAE 方法开发解决方案,但不幸的是我总是一无所获。
这是我尝试的一种解决方案,它不适用于允许我们检测另一个类是否具有名为 function()
的方法的类。 :
#include <iostream>
using namespace std;
struct sample_class
{
void function() {}
};
template<typename T>
class test_size_call
{
private:
typedef char yes;
typedef char (&no)[2];
int tester[1];
template <unsigned int>
struct helper { static const unsigned int value = 1; };
template<typename R>
static yes test(int (&a)[helper<sizeof(std::declval<R>().function(), 0)>::value]);
/* template<typename R>
static no test(...); */
public:
static const bool value = (sizeof(test<T>(tester)) == sizeof(yes));
};
int main()
{
cout << "Has function() method: " << test_size_call<sample_class>::value << endl;
return 0;
}
结果,如果你取消对包罗万象的 test
的注释功能,不断出现 false
.注释掉该函数后,我得到一个编译器错误,指出没有 test
的版本这需要 int (&)[1]
争论。我很好奇为什么 declval<R>().function()
似乎没有正确实例化。例如,如果我将其更改为非常明确的内容,例如 declval<T>().function()
然后就可以了。不幸的是,这不是 SFINAE,因为如果类(class)没有 function()
方法,而不是默默地失败,我得到一个编译器错误。
我确定我在这里遗漏了一些非常简单的东西。感谢您提供的任何帮助。
最佳答案
一定是你的编译器有问题,Clang 为以下代码正确打印了 1
和 0
:
#include <utility>
template<typename T>
class test_size_call
{
private:
typedef char yes;
typedef char (&no)[2];
int tester[1];
template <unsigned int>
struct helper { static const unsigned int value = 1; };
template<typename R>
static yes test(int (&a)[helper<sizeof(std::declval<R>().function(), 0)>::value]);
template<typename R>
static no test(...);
public:
static const bool value = (sizeof(test<T>(tester)) == sizeof(yes));
};
#include <iostream>
struct sample_class
{
void function() {}
};
struct sample_class2{};
int main()
{
std::cout << "Has function() method: " << test_size_call<sample_class>::value << '\n';
std::cout << "Has function() method 2: " << test_size_call<sample_class2>::value << '\n';
return 0;
}
关于c++ - 无法让 SFINAE 在功能检测器中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8913421/
我是 opencv 新手,正在尝试实现两个图像之间的图像匹配。为此,我试图了解特征描述符、描述符提取器和描述符匹配器之间的区别。我遇到了很多术语,并试图在 opencv 文档网站上阅读它们,但我似乎无
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 7 年前。 Improve this ques
我正在尝试弄清楚如何使用 findbugs 实现检测器。 此外,我不想创建插件,因为 findbugs 已经具有此功能。 我需要我的检测器来检查对 ClassName.getConnection()
在我的 main.cpp 中有一段摘录: Ptr fastDetector = FastFeatureDetector::create(80, true); while (true) { Ma
我想使用 orb 检测器在找到的图像周围绘制边界框,类似于此处使用筛选检测器的示例:SIFT Refrence Linked 示例使用 FlannBasedMatcher。我的代码使用 BFMatch
SURF默认情况下适用于灰色图像。我正在考虑对 HSV 图像进行 SURF。我的方法是把 channel 分成H、S和V。我用S和V做关键点检测。我试图比较 SV 与 RGB 中的关键点数量,并且在
如何使用 NSXMLDetector 查找 HTML 文件中的 RSS 链接,源代码中的标签如下所示: 我需要这个来自动检测 RSS 应用中的 RSS 链接。谢谢! 最佳答案 在您的两个示例中,您
有没有办法检测排行榜是否关闭? 当点击“highscores”时,排行榜会在很短的时间内加载,您仍然可以点击主 UI。有没有办法在单击“highscores”时停止对主 UI 的任何进一步输入? 我当
我正在使用 OpenCV 3.1 和 Visual Studio C++。 目标 我想检测角点,而不是曲线、矩形或圆形。这意味着,我想找到模糊字符的位置。这里是我感兴趣的领域: 红色区域具有更高的优先
我有一张来自显微镜的图像,需要对其进行分析(隔离 Blob )。我一直在尝试很多方法来对图像进行阈值和过滤,这给了我很好的结果,现在我正在努力获得最好的结果。 我一直在阅读拉普拉斯算子,并应用高斯拉帕
当我尝试运行包含 hog 检测器的 opencv 代码时,出现以下错误。 我一直在使用 OpenCV 做其他事情,我只在包含 hog 时遇到错误。 "Debug Assertion Failed"..
有没有办法在 OpenCV 中指定自定义 SIFT 检测器参数? 似乎FeatureDetector constructor不接受任何参数,而似乎可以在 SIFT constructor 中指定这些参
我正在尝试为 Lint 创建一个自定义规则,这将改变现有的弃用警告测试。 到目前为止我读过的文档几乎没有告诉我如何实现一个类(我认为需要)实现 Detector.JavaScanner http://
我想在opencv中实现一揽子单词。在检测器之后-> detect(img,keypoint);当我想使用keypoint.clear()清理关键点时,会检测到关键点;或者当函数想要返回时,将出现以下
我正在使用 Apache 的 Java 库 Tika(tika-core 版本。1.10)。 是否存在用于 CSV 文件的 org.apache.tika.detect.Detector?MIME 类
我正在运行以下代码: cv::Ptr fastDetector = cv::FastFeatureDetector::create(100, true, 2); cv::Ptr gpuFastDete
我致力于训练自己的 SVM。首先我想要训练它来检测人并将结果与在 opencv 中实现的 SVM 进行比较。训练后 SVM 看起来不错(我创建 xml 文件进行检查)但我无法将 svm 检测器设置
我想知道是否有人成功地使用了 Latent SVM Detector (http://docs.opencv.org/modules/objdetect/doc/latent_svm.html) 的
我正在 OpenCV 2.4 中开发一些代码,我想测试 FREAK 检测器,但出现编译错误。我包含了 feature2d.h,我该怎么做才能解决这个问题? 最佳答案 FREAK 包含在 OpenCV
我有很多使用 Lombok 构建器的带有 @NonNull 字段的类。 @Builder class SomeObject { @NonNull String mandatoryField1;
我是一名优秀的程序员,十分优秀!