我如何串联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
错误:

最佳答案

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

10-12 16:31