Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ boost::mpl::apply仅适用于类型化模板参数_C++_Boost_Boost Mpl - Fatal编程技术网

C++ boost::mpl::apply仅适用于类型化模板参数

C++ boost::mpl::apply仅适用于类型化模板参数,c++,boost,boost-mpl,C++,Boost,Boost Mpl,boost::mpl::apply元函数仅适用于模板类型参数。例如,以下工作: using namespace boost::mpl; template <class U, class S = int> struct Bar { }; using BarInt = apply<Bar<_1>, int>::type; 使用名称空间boost::mpl; 模板 结构条{}; 使用BarInt=apply::type; 但是,如果我有一个带有非类型参数的单

boost::mpl::apply
元函数仅适用于模板类型参数。例如,以下工作:

using namespace boost::mpl;

template <class U, class S = int>
struct Bar { };

using BarInt = apply<Bar<_1>, int>::type;
使用名称空间boost::mpl;
模板
结构条{};
使用BarInt=apply::type;
但是,如果我有一个带有非类型参数的单独类模板:

template <class U, int S = 50>
struct Quux { };

using QuuxInt = apply<Quux<_1>, int>::type;
模板
结构Quux{};
使用quxint=apply::type;
我得到一个编译错误,如:

/usr/include/boost/mpl/aux_/preprocessed/gcc/apply_wrap.hpp:36:8: error: no class template named ‘apply’ in ‘struct Quux<mpl_::arg<1> >’
 struct apply_wrap1
        ^
foo.cxx: In function ‘int main()’:
foo.cxx:25:21: error: expected type-specifier
     using QuuxInt = apply<Quux<_1>, int>::type;
                     ^
/usr/include/boost/mpl/aux\u/preprocessed/gcc/apply\u wrap.hpp:36:8:错误:在“struct qux”中没有名为“apply”的类模板
结构应用\u wrap1
^
foo.cxx:在函数“int main()”中:
foo.cxx:25:21:错误:应为类型说明符
使用quxint=apply::type;
^

除了为Bar创建一个子类型,将所有非类型参数转换为类型参数之外,还有什么办法可以解决这个问题吗?

没有,没有办法。你得写一个包装器。谢天谢地,如果您使包装器成为一个元函数,它接受类型参数,并将其展开为预期的非类型参数:

template <class U, class S = std::integral_constant<int, 50>>
struct QuuxWrap {
    using type = Quux<U, S::value>;
};

值是模板元编程的红头继子女。如果您将所有值提升为类型,那么一切都会变得更容易处理

不,没有办法。你得写一个包装器。谢天谢地,如果您使包装器成为一个元函数,它接受类型参数,并将其展开为预期的非类型参数:

template <class U, class S = std::integral_constant<int, 50>>
struct QuuxWrap {
    using type = Quux<U, S::value>;
};
值是模板元编程的红头继子女。如果您将所有值提升为类型,那么一切都会变得更容易处理