concatenate boost :: mpl :: string - PullRequest
       1

concatenate boost :: mpl :: string

1 голос
/ 02 ноября 2010

Как я могу объединить 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 Ошибки:

В файле из source.cpp: 3: 0: string.hpp: в экземпляре «Повышение :: MPL :: push_back_impl < повышение :: MPL :: string_tag

:: apply, boost :: mpl :: string <24930>> ': увеличить / MPL / push_back.hpp: 32: 1:
созданный из «Повышение :: MPL :: push_back < boost :: mpl :: string <>, boost :: mpl :: string <24930> 'boost / mpl / aux_ / has_type.hpp: 20: 1:
создается из 'const bool повышение :: MPL :: Окс :: has_type < повышение :: MPL :: push_back, boost :: mpl :: string <24930>>, MPL _ :: bool_ :: value 'boost / mpl / aux_ / has_type.hpp: 20: 1:
созданный из «Повышение :: MPL :: Окс :: has_type < повышение :: MPL :: push_back, boost :: mpl :: string <24930>>, MPL _ :: bool_ 'boost / mpl / aux_ / preprocessed / gcc / quote.hpp: 56: 5: создается из 'boost :: mpl :: quote2 < повышение :: MPL :: push_back :: apply, boost :: mpl :: string <24930>> ' повышение / MPL / aux_ / препроцессированный / ССАГПЗ / apply_wrap.hpp: 49: 1: созданный из «Повышение :: MPL :: apply_wrap2 < повышение :: MPL :: quote2, повышение :: MPL :: строка <>, повышение :: MPL :: строка <24930> 'boost / mpl / aux_ / preprocessed / gcc / bind.hpp: 207: 21: создается из 'boost :: mpl :: bind2 < повышение :: MPL :: quote2, mpl _ :: arg <1>, mpl _ :: arg <2> :: apply, boost :: mpl :: string <24930>> ' повышение / MPL / aux_ / препроцессированный / ССАГПЗ / apply_wrap.hpp: 49: 1: созданный из «Повышение :: MPL :: apply_wrap2 < повышение :: MPL :: защитить < повышение :: 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 < повышение :: MPL :: push_back, mpl _ :: arg <2>>, boost :: mpl :: string <>, повышение :: MPL :: строка <24930> 'boost / mpl / aux_ / preprocessed / gcc / fold_impl.hpp: 87: 85: созданный из «Повышение :: MPL :: Окс :: fold_impl < 3, boost :: mpl :: v_iter < повышение :: MPL :: вектор, повышение :: MPL :: строка <25444>, boost :: mpl :: string <25958>>, 0l , повысить :: mpl :: v_iter < повышение :: MPL :: вектор, повышение :: MPL :: строка <25444>, boost :: mpl :: string <25958>>, 3 л , boost :: mpl :: string <>, boost :: mpl :: push_back, mpl _ :: arg <2>> 'boost / mpl / fold.hpp: 39: 18: создается из' boost :: mpl :: fold < повышение :: MPL :: вектор, повышение :: MPL :: строка <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, от повышение / MPL / aux_ / inserter_algorithm.hpp: 18, из boost / mpl / copy.hpp: 20, из string.hpp: 26, из source.cpp: 3: boost / mpl / push_back.hpp: In создание «Повышение :: MPL :: push_back < повышение :: MPL :: push_back, boost :: mpl :: string <24930>>, повышение :: MPL :: строка <25444> ': boost / mpl / aux_ / has_type.hpp: 20: 1:
создается из 'const bool повышение :: MPL :: Окс :: has_type < повышение :: MPL :: push_back < повышение :: MPL :: push_back, boost :: mpl :: string <24930>>, повышение :: MPL :: строка <25444> , mpl _ :: bool_ :: value 'boost / mpl / aux_ / has_type.hpp: 20: 1:
созданный из «Повышение :: MPL :: Окс :: has_type < повышение :: MPL :: push_back < повышение :: MPL :: push_back, boost :: mpl :: string <24930>>, повышение :: MPL :: строка <25444> , mpl _ :: bool_ 'boost / mpl / aux_ / preprocessed / gcc / quote.hpp: 56: 5: создается из 'boost :: mpl :: quote2 < повышение :: MPL :: push_back

Ответы [ 2 ]

6 голосов
/ 06 декабря 2010
#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 голосов
/ 20 мая 2011
//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;
}
...