concatenate boost :: mpl :: string [英] concatenate boost::mpl::string

查看:186
本文介绍了concatenate boost :: mpl :: string的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何连接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 '>
> ;

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
错误:


在从source.cpp:3:0中包括的文件中:
string.hpp:在
的实例化中'boost :: mpl :: push_back_impl<
boost :: mpl :: string_tag


:: apply,boost :: mpl :: string&
boost / mpl / push_back.hpp:32:1:


实例化boost :: mpl :: push_back<
boost :: mpl :: string<>,boost :: mpl :: string< 24930>
'boost / mpl / aux_ / has_type.hpp:20:1:

实例化从'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:


实例化boost :: mpl :: aux :: has_type<
boost :: mpl :: push_back,
boost :: mpl :: string< 24930>>,
mpl _ :: bool_
'boost / mpl / aux_ / preprocessed / gcc /quote.hpp:56:5:
从'boost :: mpl :: quote2实例化<
boost :: mpl :: push_back
:: apply,boost :: mpl :: string< 24930>>'
boost / mpl / aux_ / preprocessed / gcc / apply_wrap.hpp:49 :1:
实例化从
'boost :: mpl :: apply_wrap2<
boost :: mpl :: quote2,
boost :: mpl :: string<>,
boost :: mpl :: string< 24930>
'boost / mpl / aux_ /preprocessed/gcc/bind.hpp:207:21:
从'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:

实例化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:
从'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:
实例化从
'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: :: 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:从这里实例化string.hpp:207:53 :错误:
'value'不是
的成员boost :: mpl :: string< 24930>'在文件
包括从
boost / mpl / back_inserter.hpp :18:0,从
boost / mpl / aux_ / inserter_algorithm.hpp:18,
从boost / mpl / copy.hpp:20,从
string.hpp:26,从源.cpp:3:
boost / mpl / push_back.hpp:In
实例化
'boost :: mpl :: push_back<
boost :: mpl :: push_back,
boost :: mpl :: string< 24930>>,
boost :: mpl :: string< 25444>
':boost / mpl / aux_ / has_type.hpp:20:1:

从'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:


实例化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:
从'boost :: mpl :: quote2实例化<
boost :: mpl :: push_back




解决方案

pre> #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>

使用命名空间boost;

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


typedef boost :: mpl :: reverse_fold<
slist,
mpl :: string<>,
boost :: mpl :: copy< mpl :: _ 1,mpl :: back_inserter< mpl :: _ >
> :: type string;

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


How I can concatenate boost::mpl::string? The following code produce errors:

#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;
}

full source here: http://liveworkspace.org/code/31902a4b1b0831d054119bc0b8923cb6 errors:

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;
}

这篇关于concatenate boost :: mpl :: string的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆