не удается скомпилировать выражение-заполнитель boost mpl fold

Я пытаюсь скомпилировать пример Statemachine из boost-mpl (находится в libs / mpl / examples / fsm / player2.cpp), но он не работает с boost версии 1.37 и g ++ 4.8.2. С буст-версией 1.56 и тем же компилятором сборка завершается успешно. К сожалению, из-за некоторых ограничений платформы я не могу перейти на версию 1.56.

Я не ожидаю, что кто-нибудь рассмотрит вышеупомянутый длинный пример, поэтому я определил минимальный фрагмент кода, который иллюстрирует проблему:

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

namespace mpl = boost::mpl;
using namespace mpl::placeholders;

//Basic queue datatype
template< class CURRENT, class NEXT >
struct queue_element
{
typedef typename CURRENT::mytype mytype;
};

//type to be put at the end of the queue
struct default_queue_element
{
};

template <class TYPE>
struct wrapper{
typedef TYPE mytype;
};

typedef mpl::vector<wrapper<int>, wrapper<char> > myvector;

//the following fold expression should create this type:
typedef queue_element<wrapper<char>, queue_element<wrapper<int>,
default_queue_element> > this_type_should_be_created;

//This typedef fails to compile with boost Version 1.37,
//but works perfectly with version 1.56
typedef typename
mpl::fold<
myvector
,default_queue_element
,queue_element<_2,_1>
>::type
generate_queue;

С boost 1.37 g ++ выдает следующие ошибки:

foldtest2.cpp: In instantiation of ‘struct queue_element<mpl_::arg<2>, mpl_::arg<1> >’:
../boost_1_37_0/boost/mpl/aux_/preprocessed/gcc/template_arity.hpp:85:5:   required from ‘const int boost::mpl::aux::template_arity_impl<queue_element<mpl_::arg<2>, mpl_::arg<1> >, 1>::value’
../boost_1_37_0/boost/mpl/aux_/preprocessed/gcc/template_arity.hpp:93:5:   required from ‘const int boost::mpl::aux::template_arity<queue_element<mpl_::arg<2>, mpl_::arg<1> > >::value’
../boost_1_37_0/boost/mpl/aux_/preprocessed/gcc/template_arity.hpp:98:30:   required from ‘struct boost::mpl::aux::template_arity<queue_element<mpl_::arg<2>, mpl_::arg<1> > >’
../boost_1_37_0/boost/mpl/aux_/preprocessed/gcc/apply.hpp:67:8:   required from ‘struct boost::mpl::apply2<queue_element<mpl_::arg<2>, mpl_::arg<1> >, default_queue_element, wrapper<int> >’
../boost_1_37_0/boost/mpl/aux_/preprocessed/gcc/fold_impl.hpp:67:85:   required from ‘struct boost::mpl::aux::fold_impl<2, boost::mpl::v_iter<boost::mpl::vector<wrapper<int>, wrapper<char> >, 0l>, boost::mpl::v_iter<boost::mpl::vector<wrapper<int>, wrapper<char> >, 2l>, default_queue_element, queue_element<mpl_::arg<2>, mpl_::arg<1> > >’
../boost_1_37_0/boost/mpl/fold.hpp:39:18:   required from ‘struct boost::mpl::fold<boost::mpl::vector<wrapper<int>, wrapper<char> >, default_queue_element, queue_element<mpl_::arg<2>, mpl_::arg<1> > >’
foldtest2.cpp:39:6:   required from here
foldtest2.cpp:15:38: error: no type named ‘mytype’ in ‘struct mpl_::arg<2>’
typedef typename CURRENT::mytype mytype;

Есть ли обходной путь, чтобы код компилировался с boost 1.37? Я искал в Интернете довольно долгое время. Если, тем не менее, на этот вопрос уже был дан ответ, я был бы признателен, если бы вы могли указать на это.

2

Решение

Похоже, это просто ошибка в этой древней (¹) версии boost.

Быстрое разделение на части говорит мне, что это было исправлено в v1.43.0 (²). Примечания к выпуску не раскрывайте секрет, но git делает:

Очевидно, что это последнее (подтверждено компиляцией против 31a2c78).

Итак, вы исправили эту единственную строку в include / boost / mpl / aux_ / template_arity.hpp (³):

sizeof(arity_helper(type_wrapper<F>(),arity_tag<N>())) - 1

должно быть

sizeof(::boost::mpl::aux::arity_helper(type_wrapper<F>(),arity_tag<N>())) - 1

Конечно, правильный способ исправить это — использовать поддерживаемую версию boost


¹ (3 ноября 2008 г.) !!

² (6 мая 2010 г.)

³ предупреждение: также присутствует в нескольких экземплярах, созданных в предварительно обработанных версиях заголовка

2

Другие решения