为什么std::generate在没有命名空间限定符的情况下是可访问的
Why is std::generate accessible without namespace qualifier?
这样编译正常吗?
#include <vector>
#include <algorithm>
int main()
{
std::vector<int> buf;
generate(buf.begin(), buf.end(), []{ return 0; });
}
(注意generate()
前面缺少std::
)
这种行为有记录吗?或者我偶然发现了编译器或库错误?在我的情况下,它将是Linux上的GCC 5.3.0和Clang 3.8.0;两者都使用libstdc++,所以可能是库错误?
这是允许的,主要是因为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*/
}
出于类似的原因是可以接受的。我们称之为依赖于参数的查找。看见https://en.wikipedia.org/wiki/Argument-dependent_name_lookup
相关文章:
- c++, 在子类中,如何在没有对象的情况下访问父类的方法?
- 是否可以在不复制的情况下访问undered_map中的元素
- 为什么不能指向指针,在没有强制转换的情况下访问结构成员?
- 为什么可以在没有实例变量的情况下访问静态回调方法中的静态成员变量?
- 如何在不设置完整路径的情况下访问 c++ 中的资源
- 如何在 getter 的父类中初始化变量的情况下访问子类中的变量
- 在不违反严格的别名规则的情况下访问进程间共享内存中的对象
- C++ 在不打开文件的情况下访问IMAGE_OPTIONAL_HEADER64?
- 如何在不使用全局变量的情况下访问 lambda 中的变量
- C++是否提供了一种在没有范围解析运算符的情况下访问类中的类的方法?
- 是否可以超载[]运算符在不定义类的情况下访问特定的字符
- 在没有捕获列表的情况下访问 lambda 中的变量
- 如何在不注册对象的情况下访问标准项模型的数据?
- 在不破坏封装的情况下访问基类元素
- 如何在不将类数据成员作为参数传递的情况下访问线程中的类数据成员
- 如何在没有 A 全局的情况下访问 A::member()
- 在不知道名称的情况下访问函数参数
- 在不破坏封装的情况下访问替代功能
- 在多继承编译器的情况下访问成员变量是否依赖?如何正确地做
- 在没有位置的情况下访问违规读取位置