代码之家  ›  专栏  ›  技术社区  ›  niXman

连接boost::mpl::string

  •  1
  • niXman  · 技术社区  · 14 年前

    如何连接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 错误:

    包含在源文件中。cpp:3:0: 'boost::mpl::push_back_impl< boost::mpl::string_标记

    boost/mpl/push_back.hpp:32:1:
    'boost::mpl::向后推< 'boost/mpl/aux_u/has_u类型。水电站:20:1:
    boost::mpl::aux::has_type< boost::mpl::字符串<24930>, 布尔_ :值“boost/mpl/aux”具有类型。hpp:20:1:
    'boost::mpl::aux::has_type< boost::mpl::向后推, boost::mpl::字符串<24930>, 布尔_ 'boost/mpl/aux_u/预处理/gcc/quote.hpp:56:5: boost::mpl::向后推 ::应用,boost::mpl::字符串<24930>>' boost/mpl/aux_u/预处理/gcc/apply_uwrap.hpp:49:1: 'boost::mpl::应用wrap2< boost::mpl::quote2, boost::mpl::字符串<gt;, 'boost/mpl/aux_u/preprocessed/gcc/bind.hpp:207:21: 从“boost::mpl::bind2<实例化; mpl::arg<1>,mpl::arg<2> ::应用,boost::mpl::字符串<24930>>' boost/mpl/aux_u/预处理/gcc/apply_uwrap.hpp:49:1: 实例化自 boost::mpl::保护< boost::mpl::bind2, mpl::arg<1>,mpl::arg<2>,0 'boost/mpl/aux_u/预处理/gcc/apply.hpp:73:1: 从“boost::mpl::apply2<实例化; boost::mpl::向后推, mpl::arg<2>>gt;,boost::mpl::string<>gt;, 'boost/mpl/auxú/preprocessed/gcc/fold戋u impl.hpp:87:85: 实例化自 3,boost::mpl::v_iter< boost::mpl::vector, boost::mpl::字符串<25444>, boost::mpl::字符串<25958>>,0升 ,boost::mpl::v_iter< boost::mpl::vector, boost::mpl::字符串<25444>, ,boost::mpl::string<>,boost::mpl::后推, mpl::参数<2>> boost::mpl::vector, boost::mpl::字符串<25444>, boost::mpl::字符串<25958>> ,boost::mpl::string<>,boost::mpl::后推, mpl::参数<2>> 'source.cpp:18:2:从这里实例化字符串。hpp:207:53:错误: “value”不是 文件中的“boost::mpl::string<24930>” boost/mpl/back_插入器。hpp:18:0,从 boost/mpl/aux_u/inserter_算法。hpp:18, string.hpp:26,来自source.cpp:3: boost/mpl/push_back.hpp:输入 实例化 'boost::mpl::向后推< boost::mpl::字符串<24930>, boost::mpl::字符串<25444>
    从'const bool'实例化 boost::mpl::aux::has_type< boost::mpl::向后推, boost::mpl::字符串<25444> ,mpl::布尔_
    实例化自 'boost::mpl::aux::has_type< boost::mpl::向后推< boost::mpl::字符串<24930>, ,mpl::布尔_ 'boost/mpl/aux_u/预处理/gcc/quote.hpp:56:5: 从“boost::mpl::quote2<实例化; boost::mpl::向后推

    2 回复  |  直到 13 年前
        1
  •  6
  •   nemethpeter    14 年前
    #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;
    }
    
        2
  •  2
  •   ra77al    14 年前
    //it's very easy to do this to have the same out put: abcdef
    
    #include <boost/mpl/string.hpp>
    #include <iostream>
    
    typedef mpl::string<'ab','cd','ef'> string;
    
    int main() {
       std::cout << mpl::c_str<string>::value << std::endl;
    }