模板内本地类成员的名称查找
Name lookup for local class members inside templates
考虑以下代码,它模拟constexpr
lambda(建议用于C++17,在C++14中不可用)。
#include <iostream>
template<int M, class Pred>
constexpr auto fun(Pred pred)
{
return pred(1) <= M;
}
template<int M>
struct C
{
template<int N>
static constexpr auto pred(int x) noexcept
{
// simulate a constexpr lambda (not allowed in C++14)
struct lambda
{
int n_, x_;
constexpr auto operator()(int y) const noexcept
{
return this->n_ * this->x_ + y;
// ^^^^ ^^^^ <---- here
}
};
return fun<M>(lambda{N, x});
}
};
int main()
{
constexpr auto res = C<7>::template pred<2>(3);
std::cout << res; // prints 1, since 2 * 3 + 1 <= 7;
}
此处,lambda
在类模板的函数模板成员中定义。令人惊讶的是,我必须this->
歧义lambda
成员变量n_
和x_
。
现场示例(带this->
,不带this->
)
我的印象是,这仅在依赖基类中是必需的,但lambda
类只是一个局部类,而不是依赖基类。
问题:有人可以指出我相关的标准语言,以便在模板中查找本地类成员的名称吗?
感谢@dyp的评论,它似乎是 Clang 3.5/3.6 中的一个错误,该错误在 Clang 3.7 的树干尖端中修复。G++ 4.8.1 通过主干尖端也可以正确编译。
相关文章:
- 不明确的成员模板查找
- enable_if继承的成员函数的名称查找错误
- 如何处理具有不同类的成员函数的函数查找表?
- C++中成员名称查找和访问声明中的歧义
- 如何通过也在向量中的指针查找作为类成员的向量的大小
- 算法在容器中查找具有给定值的元素之一的成员
- 如何使用 Clang 查找所有成员字段读/写?
- 如何查找一组类型对是否包含一个元素作为第二个成员
- 如何在具有多个成员的自定义对象的向量上使用查找
- 在C++中查找紧密成员函数名称
- 类(模板)成员函数体内部的ADL查找
- 动态链接到 c++ 静态成员字段时符号查找失败
- C++ 在向量中查找对象并在其上调用成员函数
- 查找初始化列表中的哪个成员抛出了例外
- 如何使用模板专业化来查找成员函数参数类型等
- 如何"reset" std::string的查找成员函数,一旦它到达字符串的末尾
- 设置查找成员与在列表中使用查找
- vector中没有查找成员
- Jsoncpp查找成员函数
- (C++Boost)在列表中查找成员与搜索词匹配的项目