AMDG
Istvan Buki wrote:
Dear Boost experts,
I'm trying to copy data between different types of fusion sequences
with limited success.
The example below shows what I'm trying to achieve.
<snip>
Does fusion provide a way to achieve what I'm trying to do?
The elements of the map are fusion pair. You need to
extract the second element.
#include
#include
#include
#include
namespace fields {
struct i;
struct l;
struct d;
}
template<class F>
struct result_of_second;
template
struct result_of_second {
typedef const typename Arg1::second_type& type;
};
template
struct result_of_second {
typedef typename Arg1::second_type& type;
};
template
struct result_of_second {
typedef const typename Arg1::second_type& type;
};
struct second {
template<class F>
struct result {
typedef typename result_of_second<F>::type type;
};
template<class T>
typename T::second_type& operator()(T& t) const { return(t.second); }
template<class T>
const typename T::second_type& operator()(const T& t) const {
return(t.second); }
};
int main() {
using namespace boost::fusion ;
typedef map<
pair,
pair,
pair
> map_type;
typedef vector vect_t;
vect_t tup1(1, 2, 3.0);
map_type m = tup1;
vect_t tup2 = transform(m, second());
// expected result: tup1 == tup2
}
As a side question, I was wondering whether it is possible to
synthetize the vect_t type from map_type (with MPL?)
Indeed it is possible,
typedef result_of::as_vector<
mpl::transform<
map_type,
result_of::secondmpl::_1,
mpl::back_inserter >
>::type
::type vect_t;
In Christ,
Steven Watanabe