是否有一种方法来恢复原来的模板模板类嵌入在boost

Is there a way to recover original template template class enbeded in boost mpl quote?

本文关键字:boost 原来 恢复 方法 一种 是否      更新时间:2023-10-16

我引用了一个模板类,将其放入mpl::vector中,这样做:

boost::mpl::vector<int, boost::mpl::quote2<std::pair>>

然后,我像这样得到第二个元素:

using A=typename boost::mpl::at<T, boost::mpl::int_<2>>::type;
我现在需要将原始模板类传递给这样的类:
template<class A, template<class, class> class C>
class B{
    C<A, B*> _c;
};

我尝试使用apply或bind,但无法让B接受第二个参数。

我得到这样的错误:

error: template argument for template template parameter must be a class template or type alias template
编辑:

示例代码:

#include <boost/mpl/vector.hpp>
#include <boost/mpl/quote.hpp>
#include <boost/mpl/at.hpp>
template<class, class> class A{};
template<class A, template<class, class> class C>
class B{
    C<A, B*> _c;
};
using T=boost::mpl::vector<int, boost::mpl::quote2<A>> ;
using T1=typename boost::mpl::at<T, boost::mpl::int_<0>>::type;
using T2=typename boost::mpl::at<T, boost::mpl::int_<1>>::type;
int main(){
    B<T1, T2> b;
    return 0;
}

:

error: template argument for template template parameter must be a class template or type alias template B<T1, T2> b;

MPL在很大程度上仍然是一个c++ 03库,你正试图让它生成一些在c++ 11之前概念上不存在的东西。我怀疑让quote在这种情况下工作是语法的巧合,而不是预期的功能。

下面的代码可以在VC2013中成功编译:

#include <boost/mpl/vector.hpp>
#include <boost/mpl/quote.hpp>
#include <boost/mpl/apply.hpp>
#include <boost/mpl/at.hpp>
template<class, class> class A{};
template<class A, template<class, class> class C>
class B{
    C<A, B*> _c;
};
using T = boost::mpl::vector < int, boost::mpl::quote2<A> > ;
using T1 = boost::mpl::at<T, boost::mpl::int_<0>>::type;
using T2 = boost::mpl::at<T, boost::mpl::int_<1>>::type;
template<typename X1, typename X2>
using TT2 = typename boost::mpl::apply<T2, X1, X2>::type;
int main(int argc, char* argv[])
{
    B<T1, TT2> b;
    return 0;
}