|
Boost : |
From: Alexander Nasonov (alnsn-mycop_at_[hidden])
Date: 2003-04-29 02:56:10
Joaquín Mª López Muñoz wrote:
> Seems like a common enough problem, but I haven't been able to
> find any facility to construct a MPL Sequence conformant type from
> a boost::tuple. Has anybody run into the same problem? If so, pointers
> to info / snippets of code are most welcome.
Recently I implemented function_arguments<Signature> as MPL random access
sequence. I also implemented sig2tuple<Signature>. So, I'm able to create
an MPL sequence from function signature, then modify it (add, remove or
transform arguments) and then convert it into tuple. You can take a look at
code here:
1. Definition of function_arguments
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/cpp-experiment/dynamic_any/boost/dynamic_any/aux/function_arguments.hpp?rev=1.2&content-type=text/vnd.viewcvs-markup
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/cpp-experiment/dynamic_any/boost/dynamic_any/aux/generated/function_arguments_impl10.hpp?rev=1.1&content-type=text/vnd.viewcvs-markup
2. Definition of sig2tuple and use of function_arguments
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/cpp-experiment/dynamic_any/boost/dynamic_any/function.hpp?rev=1.31&content-type=text/vnd.viewcvs-markup
I recommend using function_arguments sequence only for types which are
function agruments. I can suggest that you need more then that. This is the
other way of doing it:
template<class Tuple>
struct tuple2vector;
// Less specialized first
template<class T1, class T2, class T3, ..., class T10>
struct tuple2vector< tuple<T1,T2,T3,...,T10> >
{
typedef mpl::vector<T1,T2,T3,...,T10> type;
};
// ...
template<class T1, class T2>
struct tuple2vector< tuple<T1,T2> >
{
typedef mpl::vector<T1,T2> type;
};
template<class T1>
struct tuple2vector< tuple<T1> >
{
typedef mpl::vector<T1> type;
};
template<>
struct tuple2vector< tuple<> >
{
typedef mpl::vector<> type;
};
Alternatively, you can implement MPL conformant sequence
tuple_sequence<Tuple>. It's not so hard as you can imagine.
(Question to MPL's authors: when it will be documented?).
-- Alexander Nasonov Remove minus and all between minus and at from my e-mail for timely response
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk