extending MPL sequences beyound 20 items

  • Follow


    I have a state machine similiar if not identical to that described
in "C++ Template Metaprogramming". I need to extend the sequence
[vector or list which ever is easier] to 40 items.  What is the easiest
way to define a 'transition table' with more than 20 lines.

class c_filter:public state_machine<c_filter>
{
// ...
    typedef typename state_machine<c_filter>  base_t;

typedef boost::mpl::vector
<
    base_t::row<Current,Event,Next,Action>,
    // about 30 such lines
> transition table;
// ...
};

is currently used.  What is the easiest way to get this to compile
compile, with over template args to boost::mpl::vector< ...> above.
There maybe cosmetic differences in the state machine but it is
logically the same as in Chapter 11. It works if transition_table has
20 or fewer arguments.

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Reply cbarron413 (16) 3/25/2006 11:05:17 AM

Carl Barron <cbarron413@adelphia.net> writes:

>     I have a state machine similiar if not identical to that described
> in "C++ Template Metaprogramming". I need to extend the sequence
> [vector or list which ever is easier] to 40 items.  What is the easiest
> way to define a 'transition table' with more than 20 lines.
>
> class c_filter:public state_machine<c_filter>
> {
> // ...
>     typedef typename state_machine<c_filter>  base_t;
>
> typedef boost::mpl::vector
> <
>     base_t::row<Current,Event,Next,Action>,

You don't need to qualify row with base_t::
That just makes your transition table more verbose to no benefit.

>     // about 30 such lines
>> transition table;
> // ...
> };
>
> is currently used.  What is the easiest way to get this to compile
> compile, with over template args to boost::mpl::vector< ...> above.
> There maybe cosmetic differences in the state machine but it is
> logically the same as in Chapter 11. It works if transition_table has
> 20 or fewer arguments.

Use the numbered form of mpl::vector.  For example, if you have 37
rows:

#include <boost/mpl/vector/vector40.hpp>

         typedef boost::mpl::vector37<
             row< ... >
           , row< ... >
           ...
         >

HTH,
-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Reply David 3/26/2006 12:09:50 AM


In article <uirq2k11u.fsf@boost-consulting.com>, David Abrahams
<dave@boost-consulting.com> wrote:

> Carl Barron <cbarron413@adelphia.net> writes:
>
> > typedef boost::mpl::vector
> > <
> >     base_t::row<Current,Event,Next,Action>,
> 
> You don't need to qualify row with base_t::
> That just makes your transition table more verbose to no benefit.
> 
   I did when the machine was templated on an input iterator and I just
did not change that when other problems which  I forget appeared with a
templated machine. something about the member function pointers does
not
work with 

   template <class T>
   class machine:public state_machine<machine<T> >
   {
   //...
   };
   But I forgot the error message, with non templated machine all is
fine...

> >     // about 30 such lines
> >> transition table;
> > // ...
> > };
> >
> > is currently used.  What is the easiest way to get this to compile
> > compile, with over template args to boost::mpl::vector< ...> above.
> > There maybe cosmetic differences in the state machine but it is
> > logically the same as in Chapter 11. It works if transition_table has
> > 20 or fewer arguments.
> 
> Use the numbered form of mpl::vector.  For example, if you have 37
> rows:
> 
  Thanks, I will remember  this...
> #include <boost/mpl/vector/vector40.hpp>
> 
>          typedef boost::mpl::vector37<
>              row< ... >
>            , row< ... >
>            ...
>          >
> 
> HTH,

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Reply Carl 3/26/2006 12:45:35 PM

Carl Barron wrote:
> In article <uirq2k11u.fsf@boost-consulting.com>, David Abrahams
> <dave@boost-consulting.com> wrote:
>
>> Carl Barron <cbarron413@adelphia.net> writes:
>>
>>> typedef boost::mpl::vector
>>> <
>>>     base_t::row<Current,Event,Next,Action>,
>> You don't need to qualify row with base_t::
>> That just makes your transition table more verbose to no benefit.
>>
>    I did when the machine was templated on an input iterator and I  
> just
> did not change that when other problems which  I forget appeared  
> with a
> templated machine. something about the member function pointers does
> not
> work with
>
>    template <class T>
>    class machine:public state_machine<machine<T> >
>    {
>    //...
>    };
>    But I forgot the error message, with non templated machine all is
> fine...

Try

    using state_machine<machine<T> >::row;


--
David Abrahams
Boost Consulting
http://www.boost-consulting.com

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Reply David 3/26/2006 5:47:05 PM

3 Replies
96 Views

(page loaded in 0.077 seconds)

4/29/2013 7:08:26 AM


Reply: