在下面,为什么调用bar不明确的实例化,而非模板重载函数foo是不明确的.nullptr取而代之的是相同的NULL
#include <iostream>
template<typename T>
void bar (T*)
{
std::cout << "bar(T*)" << std::endl;
}
template<typename T>
void bar (typename T::value_type *)
{
std::cout << "bar(T::value_type*)" << std::endl;
}
struct A
{
using value_type = int;
};
void foo (A::value_type*)
{
std::cout << "foo(A::value_type *)" << std::endl;
}
void foo (A*)
{
std::cout << "foo(A *)" << std::endl;
}
int main ()
{
bar<A> (NULL);
foo (NULL); // ambigous
}
Run Code Online (Sandbox Code Playgroud)
编辑:要清楚.我希望foo过载是模棱两可的.我不明白为什么 …
STL中的并行版本的搜索算法(例如std :: find,std :: find_if)是否保证将迭代器返回到与该条件匹配的范围中的第一个元素?
文档没有明确指出是否是这种情况 - 并且在'C++ Concurrency in Action'中有一个特定的实现不返回第一个元素.