无法使用模板参数编译boost Meta State Machine

问题描述 投票:1回答:1

无法确定TSm_中违反了哪条规则。编译Sm_,TSm_不是:

错误C2974:'boost :: mpl :: vector':'T0'的模板参数无效,类型为expected

错误C2974:'boost :: mpl :: vector':'T3'的模板参数无效,类型为expected

不同之处在于TSm_是模板而Sm_不是。

#include <boost/msm/back/state_machine.hpp>
#include <boost/msm/front/state_machine_def.hpp>

namespace msm = boost::msm;
namespace mpl = boost::mpl;

struct Event {};

class Sm_ : public msm::front::state_machine_def<Sm_>
{
public:
    using Me = Sm_;
    struct First : public msm::front::state<>
    {};
    using initial_state = First;
    struct Second : public msm::front::state<>
    {};
    void trans(const Event& /*e*/)
    {}
    struct transition_table : public mpl::vector<
        a_row<First, Event, Second, &Me::trans>
    >
    {};
};

using Sm = msm::back::state_machine<Sm_>;

// broken one

enum class Side : char
{
    Buy = 0, Sell = 1
};

template <Side side>
class TSm_ : public msm::front::state_machine_def<TSm_<side>>
{
public:
    using Me = TSm_<side>;
    using Base = msm::front::state_machine_def<Me>;
    using Base::a_row;
    struct First : public msm::front::state<>
    {};
    using initial_state = First;
    struct Second : public msm::front::state<>
    {};
    void trans(const Event& /*e*/)
    {}
    struct transition_table : public mpl::vector<
        a_row<First, Event, Second, &Me::trans> // compilation is failed here
    >
    {};
};

template <Side side>
using TSm = msm::back::state_machine<TSm_<side>>;

请帮忙

更新

我发现如何编译它:因为a_row不是类型而是模板,它的别名也应该是模板

struct Begin {};

template <Side side>
class TSm_ : public msm::front::state_machine_def<TSm_<side>>
{
public:
    //-----------------------------------------------------------------------------------------------------
    using Me = TSm_<side>;
    using Base = msm::front::state_machine_def<Me>;
    template<
        typename T1
        , class Event
        , typename T2
        , void (Me::*action)(Event const&)
    >
    using a_row = typename Base::a_row;
    //-----------------------------------------------------------------------------------------------------
    struct First : public msm::front::state<>
    {};
    //-----------------------------------------------------------------------------------------------------
    using initial_state = First;
    //-----------------------------------------------------------------------------------------------------
    struct Second : public msm::front::state<>
    {};
    //-----------------------------------------------------------------------------------------------------
    void trans(const Begin& /*e*/)
    {}
    //-----------------------------------------------------------------------------------------------------
    struct transition_table : public mpl::vector<
        a_row<First, Begin, Second, &Me::trans>
    >
    {};
};

这是正确的,是这个规则2) An alias template is a template which, when specialized, is equivalent to the result of substituting the template arguments of the alias template for the template parameters in the type-id

c++ boost
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.