|
Boost Users : |
Subject: Re: [Boost-users] [MPL] How to use a mpl::map
From: Stefan Strasser (strasser_at_[hidden])
Date: 2013-03-15 06:05:06
Am 15.03.2013 08:52, schrieb Daniele Barzotti:
> // Map of types. The key is the Message opCode
> typedef typename mpl::map< mpl::pair<mpl::int_[100],
> PBMessage<MSG_METHOD_CONNECT> >,
> mpl::pair<mpl::int_[101],
> PBMessage<MSG_EVENT_CONNECT> >,
> > TMessageMap;
typedef mpl::map< mpl::pair<mpl::int_<100>,
PBMessage<MSG_METHOD_CONNECT> >,
mpl::pair<mpl::int_<101>,
PBMessage<MSG_EVENT_CONNECT> >
> TMessageMap;
>
> // The Message type
> template < typename MessageMap, int opCode >
> typedef typename mpl::at<MessageMap, mpl::int_<opCode> >::type::value
> TMessage;
there are no templated typedefs, just use
mpl::at<TMessageMap,mpl::int_<100> >::type to look up the type for an
"opcode".
However, IIUC what you're trying to do, you won't know the op code at
compile time, as you're reading it at runtime from some kind of message
stream.
Maybe the following code is helpful to you. it does something very
similar (read log entries of different types from a file).
it uses a MPL vector instead of a map though and assigns the Ids ("op
codes") continuously, so the first entry has id 1, the second Id 2, ...
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net