【发布时间】:2016-03-17 20:32:54
【问题描述】:
struct foo {
void bar(int&&) && { }
};
template<class T>
using bar_t = void (std::decay_t<T>::*)(int&&) /* add && if T is an rvalue reference */;
int main()
{
using other_t = void (foo::*)(int&&) &&;
static_assert(std::is_same<bar_t<foo&&>, other_t>::value, "not the same");
return 0;
}
我想要那个
-
bar_t<T>产生void (foo::*)(int&&)如果T = foo -
bar_t<T>产生void (foo::*)(int&&) const如果T = foo const -
bar_t<T>产生void (foo::*)(int&&) &如果T = foo& -
bar_t<T>产生void (foo::*)(int&&) const&如果T = foo const&
等等。我怎样才能做到这一点?
【问题讨论】:
-
这个的用例是什么?
-
分配 CV 限定符的方式与您可以通过完美转发分配左值/右值的方式相同。假设 CV 和 LR 不变性通常是不正确的,但提供它确实很有价值,特别是如果它是您可以定义为特征的属性。您不必为每个变体编写单独的逻辑 - 因此是“不变性” - 您将能够归纳推理这些变体的组合。
标签: c++ templates function-pointers c++14 member-function-pointers