为什么我在这里不需要Sfinae
Why do I not need SFINAE here
我试图为Sfinae做一个激励榜样我注意到您不需要以下内容:
#include <iostream>
using namespace std;
template<typename T>
struct Foo
{
void add(int count, const T& val) // add "count" number of val's
{
cout << "count, val" << endl;
}
template<typename It>
void add(It beg, It end) // add items [beg,end)
{
cout << "beg, end" << endl;
}
};
int main()
{
int a=1;
int xx[] = {1,2,3};
Foo<int> foo;
foo.add(xx, xx+3);
foo.add(2, a);
}
此编译,运行和打印:
乞讨,结束
计数,val
在这里尝试
我不明白为什么第二个呼叫add
不模棱两可。
基本上:
- 两个过载都是可行的。
- 两者都是匹配的,没有转换/促销。
-
add(int count, const T& val)
是非模板。
相关文章:
- 在两个类中共享相同的函数调用,并在不需要时避免空实例化
- 是否有类似std::lower_bound的函数,而不需要排序/分区输入
- 为什么output_editor Concept不需要output_e迭代器标记
- 在除法中不需要四舍五入
- 与C代码相比,为什么C++代码不需要"#define _POSIX_C_SOURCE 200809L"?
- 将值从另一个数组写入数组,不包括不需要的值 C++
- C++ 写入路径名中包含不需要的空字符的文件
- 是否有必要获取锁并在不需要唤醒线程时通知condition_variable?
- 使用 assimp 加载模型 - 不需要提升?
- 为什么转换函数声明不需要至少一个定义类型说明符
- 返回不需要的值的二叉搜索程序
- SFINAE不能防止模棱两可的操作员过载吗?
- 当我不需要数据库中的所有值时,如何部分初始化 c++ 对象?
- C++:用户输入会产生不需要的行为
- 如何在不需要LIBCD.lib的情况下在Visual Studio 6中编译C项目
- 为什么python需要全局关键字而C/C++不需要?
- 将一个宏传递到另一个宏而不是直接传递内容时会出现不需要的额外"空"参数
- 为什么我们需要在 C++ 中检查空指针,而在 Java 中不需要?
- 为什么复制构造函数不需要检查输入对象是否指向自身?
- 为什么我在这里不需要Sfinae