【发布时间】:2015-06-02 14:34:26
【问题描述】:
我有一个不同类型的 boost mpl 向量,想知道该向量中是否有一种特定类型。但是该类型包含一个模板参数,它是一个 boost 占位符(我想在之后替换它)
代码:
#define BOOST_MPL_LIMIT_VECTOR_SIZE 20
#define BOOST_MPL_LIMIT_MAP_SIZE 20
#include <boost/typeof/std/utility.hpp>
#include <boost/mpl/placeholders.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/mpl/contains.hpp>
namespace bmpl = boost::mpl;
template< class In, class Out = bmpl::_1 >
struct BSI{
typedef typename Out::FrameType FrameType;
};
int main(){
typedef BSI<float> foot;
typedef bmpl::vector< int, foot > vec;
typename bmpl::find_if< vec, bmpl::same_as<foot> >::type x;
}
问题是:Boost 似乎对占位符感到困惑,并尝试应用我的占位符。当然,我可以编写自己的占位符和应用程序,但是这可以通过 boost 本身实现吗?
【问题讨论】:
-
如果您的意思是您将 Boost MPL 的实现细节用于您自己的元编程库语义,那么您得到了应得的:/ Boost MPL 可能允许您“引用”这个地方-持有人,但我不会指望它(考虑到 MPL 的年龄和支持的平台)
-
之后我想步行使用 boost::apply。这就是 boost 占位符的用途,不是吗?
-
除了您现在还想将它们视为非魔法实体。这是一个或另一个。您可能可以使用自己的琐碎报价:
template<typename T> struct quoted { typedef T type; };并在您要“步行申请”时解压:)
标签: c++ boost template-meta-programming