【问题标题】:Boost MPL at template overload missing?缺少模板重载时提升 MPL?
【发布时间】:2013-07-08 21:27:53
【问题描述】:

我正在尝试使用 boost-mpl 的地图容器进行基于策略的设计的 POC。 (code here)

我使用 mpl::map 传递我的策略,默认情况下它是空的:

typedef boost::mpl::map<> DefaultPolicy;

为了获得该政策,我尝试了以下方法:

typedef typename boost::mpl::at<TPolicy, LogPK, DefaultLogP>::type LoggingPolicy;

相反,我在使用 g++ 4.81(以及使用 clang++ 3.3 的等效错误)时遇到以下错误:

main.cpp:49:61: error: wrong number of template arguments (3, should be 2)
    typedef typename boost::mpl::at<TPolicy, LogPK, DefaultLogP>::type LoggingPolicy;
                                                               ^

boost 文档mentions at 模板的三参数重载。看起来它不在#include &lt;boost/mpl/at.hpp&gt; 中。我什至通过 boost 代码搜索了这个重载,但没有成功。我发现的唯一模板是带有两个参数的模板。我在谷歌上搜索这个问题失败了(“at”太常见了)。

这是一个 boost 文档错误,还是有人知道如何使用这个 mpl::at 重载?

【问题讨论】:

  • facepalm。我终于找到了这个(至少)三年前的文档错误的trac issue

标签: boost-mpl


【解决方案1】:

只有 2 种版本。不幸的是,该文档是错误的,并且一直存在。但你总是可以自己滚动

template <typename Seq, typename Key, typename Def>
struct at_def
: mpl::eval_if<
    typename mpl::has_key<Seq, Key>::type,
    mpl::at<Seq, Key>,
    mpl::identity<Def>
    >
{ }

【讨论】:

    猜你喜欢
    • 2015-09-12
    • 1970-01-01
    • 1970-01-01
    • 2014-11-16
    • 1970-01-01
    • 2011-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多