【问题标题】:How to apply an mpl::transform to an mpl::string?如何将 mpl::transform 应用于 mpl::string?
【发布时间】:2010-06-11 12:01:04
【问题描述】:

我正在尝试对mpl::string 应用转换,但无法编译。我正在使用 MS VC++2010 和 Boost 1.43.0。代码:

#include <boost/mpl/string.hpp>
#include <boost/mpl/vector_c.hpp>
#include <boost/mpl/transform.hpp>
#include <boost/mpl/plus.hpp>
#include <boost/mpl/arithmetic.hpp>

using namespace boost;

int main() {

    // this compiles OK
    typedef mpl::vector_c<int, 'abcd', 'efgh'> numbers;
    typedef mpl::transform<numbers, mpl::plus<mpl::_1, mpl::int_<1> > >::type result_numbers;

    // this doesn't (error C2039: 'value' : is not a member of 'boost::mpl::has_push_back_arg')
    typedef mpl::string<'abcd', 'efgh'> chars;
    typedef mpl::transform<chars, mpl::plus<mpl::_1, mpl::int_<1> > >::type result_chars;

}

我已在http://paste.ubuntu.com/447759/ 发布了完整的错误消息。

MPL 文档说mpl::transform 需要Forward Sequence,而mpl::stringBidirectional Sequence,我认为它是Forward Sequence 的一种,所以我认为它可以工作。

我做错了什么,还是这完全不可能?如果有,为什么?

谢谢!

【问题讨论】:

  • “我做错了吗?” 嗯,尝试在 C++ 中进行模板元编程? 鸭子
  • 如果您使用的是 MS VC 2010,为什么要在 Ubuntu 网站上发布您的问题?

标签: c++ templates boost metaprogramming boost-mpl


【解决方案1】:

事实证明,如果我使用transform_view,它就可以工作。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2011-05-03
  • 1970-01-01
  • 1970-01-01
  • 2023-03-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多