c++ - 连接 boost::mpl::string

标签 c++ string boost boost-mpl

我如何连接 boost::mpl::string? 以下代码产生错误:

#include <iostream>
#include <boost/mpl/vector.hpp>
#include <boost/mpl/string.hpp>
#include <boost/mpl/fold.hpp>
#include <boost/mpl/placeholders.hpp>
#include <boost/mpl/push_back.hpp>

typedef boost::mpl::vector<
   boost::mpl::string<'ab'>,
   boost::mpl::string<'cd'>,
   boost::mpl::string<'ef'>
> slist;

typedef boost::mpl::fold<
   slist,
   boost::mpl::string<>,
   boost::mpl::push_back<boost::mpl::_1, boost::mpl::_2>
>::type string;

int main() {
   std::cout << boost::mpl::c_str<string>::value << std::endl;
}

完整资源在这里:http://liveworkspace.org/code/31902a4b1b0831d054119bc0b8923cb6 错误:

In file included from source.cpp:3:0: string.hpp: In instantiation of 'boost::mpl::push_back_impl< boost::mpl::string_tag

::apply, boost::mpl::string<24930> >': boost/mpl/push_back.hpp:32:1:
instantiated from 'boost::mpl::push_back< boost::mpl::string<>, boost::mpl::string<24930> ' boost/mpl/aux_/has_type.hpp:20:1:
instantiated from 'const bool boost::mpl::aux::has_type< boost::mpl::push_back, boost::mpl::string<24930> >, mpl_::bool_ ::value' boost/mpl/aux_/has_type.hpp:20:1:
instantiated from 'boost::mpl::aux::has_type< boost::mpl::push_back, boost::mpl::string<24930> >, mpl_::bool_ ' boost/mpl/aux_/preprocessed/gcc/quote.hpp:56:5: instantiated from 'boost::mpl::quote2< boost::mpl::push_back ::apply, boost::mpl::string<24930> >' boost/mpl/aux_/preprocessed/gcc/apply_wrap.hpp:49:1: instantiated from 'boost::mpl::apply_wrap2< boost::mpl::quote2, boost::mpl::string<>, boost::mpl::string<24930> ' boost/mpl/aux_/preprocessed/gcc/bind.hpp:207:21: instantiated from 'boost::mpl::bind2< boost::mpl::quote2, mpl_::arg<1>, mpl_::arg<2> ::apply, boost::mpl::string<24930> >' boost/mpl/aux_/preprocessed/gcc/apply_wrap.hpp:49:1: instantiated from 'boost::mpl::apply_wrap2< boost::mpl::protect< boost::mpl::bind2, mpl_::arg<1>, mpl_::arg<2> >, 0 , boost::mpl::string<>, boost::mpl::string<24930> ' boost/mpl/aux_/preprocessed/gcc/apply.hpp:73:1: instantiated from 'boost::mpl::apply2< boost::mpl::push_back, mpl_::arg<2> >, boost::mpl::string<>, boost::mpl::string<24930> ' boost/mpl/aux_/preprocessed/gcc/fold_impl.hpp:87:85: instantiated from 'boost::mpl::aux::fold_impl< 3, boost::mpl::v_iter< boost::mpl::vector, boost::mpl::string<25444>, boost::mpl::string<25958> >, 0l , boost::mpl::v_iter< boost::mpl::vector, boost::mpl::string<25444>, boost::mpl::string<25958> >, 3l , boost::mpl::string<>, boost::mpl::push_back, mpl_::arg<2> > ' boost/mpl/fold.hpp:39:18: instantiated from 'boost::mpl::fold< boost::mpl::vector, boost::mpl::string<25444>, boost::mpl::string<25958> > , boost::mpl::string<>, boost::mpl::push_back, mpl_::arg<2> > ' source.cpp:18:2: instantiated from here string.hpp:207:53: error: 'value' is not a member of 'boost::mpl::string<24930>' In file included from boost/mpl/back_inserter.hpp:18:0, from boost/mpl/aux_/inserter_algorithm.hpp:18, from boost/mpl/copy.hpp:20, from string.hpp:26, from source.cpp:3: boost/mpl/push_back.hpp: In instantiation of 'boost::mpl::push_back< boost::mpl::push_back, boost::mpl::string<24930> >, boost::mpl::string<25444> ': boost/mpl/aux_/has_type.hpp:20:1:
instantiated from 'const bool boost::mpl::aux::has_type< boost::mpl::push_back< boost::mpl::push_back, boost::mpl::string<24930> >, boost::mpl::string<25444> , mpl_::bool_ ::value' boost/mpl/aux_/has_type.hpp:20:1:
instantiated from 'boost::mpl::aux::has_type< boost::mpl::push_back< boost::mpl::push_back, boost::mpl::string<24930> >, boost::mpl::string<25444> , mpl_::bool_ ' boost/mpl/aux_/preprocessed/gcc/quote.hpp:56:5: instantiated from 'boost::mpl::quote2< boost::mpl::push_back

最佳答案

#include <iostream>
#include <boost/mpl/vector.hpp>
#include <boost/mpl/string.hpp>
#include <boost/mpl/fold.hpp>
#include <boost/mpl/front.hpp>
#include <boost/mpl/deref.hpp>
#include <boost/mpl/placeholders.hpp>
#include <boost/mpl/push_back.hpp>

using namespace boost;

typedef boost::mpl::vector<
   boost::mpl::string<'a','b'>,
   boost::mpl::string<'c','d'>,
   boost::mpl::string<'e','f'>
> slist;


typedef boost::mpl::reverse_fold<
   slist,
   mpl::string<>,
   boost::mpl::copy<mpl::_1, mpl::back_inserter<mpl::_2> >
>::type string;

int main() {
   std::cout << boost::mpl::c_str<string>::value << std::endl;
}

关于c++ - 连接 boost::mpl::string,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4077369/

相关文章:

c++ - opengl/glut 中的 renderDisplayFunc 不止一次调用 myfunc

Java ReplaceAll(..) 和正则表达式

php - 比较数据库中的 200.000 条文本

c++ - boost asio 绑定(bind) : bad file descriptor

c++ - C++11 中的 hash_value 函数

c++ - 构建 XPCOM Mozilla 示例组件

c++ - 如何使该函数与 FILE 一起使用? C++

c++ - 为什么 signalhandler 不输出任何东西?

java - 如何从字符串变量中获取小时和分钟?

c++ - 将 uin32_t 写入 asio::streambuf