我正在尝试使用C ++元编程,一切都进行得很顺利,除非我尝试编译这个重现器:
struct _0 {
template<typename F, typename X>
using apply = X;
};
struct Z {
template<typename F>
struct impl {
struct C {
template<typename X>
struct closure {
template<typename V>
struct impl {
// Broken out to help with debugging
using XX = typename X::template apply<X>;
using XXV = typename XX::template apply<V>;
};
template<typename V>
using apply = typename impl<V>::XXV;
};
template<typename X>
using apply = typename F::template apply<closure<X>>;
};
using exec = typename C::template apply<C>;
};
template<typename F>
using apply = typename impl<F>::exec;
};
struct True {
template<typename Consequent, typename Alternative>
using apply = Consequent;
};
struct False {
template<typename Consequent, typename Alternative>
using apply = Alternative;
};
struct zero {
struct constantly_false {
template<typename>
using apply = False;
};
template<typename N>
using apply = typename N::template apply<constantly_false, True>;
};
struct mintest {
template<typename F>
struct closure {
template<typename N>
using apply =
typename zero::apply<N>::template apply<
_0, typename F::template apply<_0>>;
};
template<typename F>
using apply = closure<F>;
};
using test = Z::apply<mintest>;
using F = test::apply<_0>;
int main() {
return 0;
};
我最终得到错误:
reproducer.cc: In instantiation of ‘struct Z::impl<mintest>::C::closure<Z::impl<mintest>::C>::impl<_0>’:
reproducer.cc:19:44: required by substitution of ‘template<class F> template<class X> template<class V> using apply = typename Z::impl<F>::C::closure<X>::impl::XXV [with V = _0; X = Z::impl<mintest>::C; F = mintest]’
reproducer.cc:56:42: required from ‘struct mintest::closure<Z::impl<mintest>::C::closure<Z::impl<mintest>::C> >’
reproducer.cc:63:15: required from here
reproducer.cc:16:53: error: no class template named ‘apply’ in ‘using XX = Z::impl<mintest>::C::apply<Z::impl<mintest>::C> {aka struct mintest::closure<Z::impl<mintest>::C::closure<Z::impl<mintest>::C> >}’
using XXV = typename XX::template apply<V>;
这对我没有意义。 mintest :: closure没有专门化,所以我认为每个实例都应该适用于它。我尝试使用Clang并得到了同样的错误,这是我的线索,我只是听不懂。
谢谢。