Nik*_* C. 9 c++ gcc namespaces clang c++11
编译好是正常的吗?
#include <vector>
#include <algorithm>
int main()
{
std::vector<int> buf;
generate(buf.begin(), buf.end(), []{ return 0; });
}
Run Code Online (Sandbox Code Playgroud)
(注意std::前面缺少的generate())
这种行为是否记录在某处?或者我偶然发现了编译器或库错误?在我的例子中,在Linux上是GCC 5.3.0和Clang 3.8.0; 两者都使用libstdc ++,所以也许库bug?
这是允许的,主要是因为 的参数generate位于std.
代码如下
namespace Foo
{
struct B{};
void foo(const B&);
}
int main()
{
Foo::B b; /*Requires Foo::*/
foo(b); /*Does not require Foo:: as that is gleaned from the argument*/
}
Run Code Online (Sandbox Code Playgroud)
出于类似的原因是可以接受的。我们称之为参数依赖查找。请参阅https://en.wikipedia.org/wiki/Argument-dependent_name_lookup