1 | #include <boost/fusion/include/map.hpp>
|
---|
2 | #include <boost/fusion/include/pair.hpp>
|
---|
3 | #include <boost/fusion/include/at_key.hpp>
|
---|
4 | #include <boost/fusion/include/mpl.hpp>
|
---|
5 |
|
---|
6 | #include <boost/mpl/vector.hpp>
|
---|
7 | #include <boost/mpl/copy.hpp>
|
---|
8 | #include <boost/mpl/zip_view.hpp>
|
---|
9 | #include <boost/mpl/back_inserter.hpp>
|
---|
10 | #include <boost/mpl/for_each.hpp>
|
---|
11 | #include <boost/mpl/range_c.hpp>
|
---|
12 | #include <boost/mpl/transform.hpp>
|
---|
13 | #include <boost/mpl/placeholders.hpp>
|
---|
14 |
|
---|
15 | namespace detail {
|
---|
16 |
|
---|
17 | template <typename T>
|
---|
18 | struct add_pair_size
|
---|
19 | {
|
---|
20 | typedef boost::fusion::pair<T, size_t> type;
|
---|
21 | };
|
---|
22 |
|
---|
23 | template <typename TTypes>
|
---|
24 | struct types_to_size_type
|
---|
25 | {
|
---|
26 | typedef typename boost::mpl::transform<
|
---|
27 | TTypes,
|
---|
28 | add_pair_size<boost::mpl::placeholders::_1>,
|
---|
29 | boost::mpl::back_inserter<boost::mpl::vector<> > >::type size_seq;
|
---|
30 | typedef typename boost::fusion::result_of::as_map<size_seq>::type type;
|
---|
31 | };
|
---|
32 |
|
---|
33 | template <typename TTypes0, typename TSize0, typename TTypes1, typename TSize1>
|
---|
34 | struct copy_size
|
---|
35 | {
|
---|
36 | copy_size(const TSize0& size0, TSize1& size1)
|
---|
37 | : _size0(size0), _size1(size1)
|
---|
38 | {}
|
---|
39 |
|
---|
40 | typedef void result_type;
|
---|
41 |
|
---|
42 | template <typename TIndex>
|
---|
43 | void operator()(TIndex) const
|
---|
44 | {
|
---|
45 | typedef typename boost::mpl::at<TTypes0, TIndex>::type Type0;
|
---|
46 | typedef typename boost::mpl::at<TTypes1, TIndex>::type Type1;
|
---|
47 |
|
---|
48 | boost::fusion::at_key<Type1>(_size1) = boost::fusion::at_key<Type0>(_size0);
|
---|
49 | }
|
---|
50 |
|
---|
51 | private:
|
---|
52 | const TSize0& _size0;
|
---|
53 | TSize1& _size1;
|
---|
54 | };
|
---|
55 |
|
---|
56 | } // namespace detail
|
---|
57 |
|
---|
58 | int main()
|
---|
59 | {
|
---|
60 | typedef boost::mpl::vector<int, bool> Types0;
|
---|
61 | typedef boost::mpl::vector<char, short> Types1;
|
---|
62 |
|
---|
63 | typedef boost::mpl::zip_view<boost::mpl::vector<Types0, Types1> > ZippedTypes;
|
---|
64 | typedef boost::mpl::copy<ZippedTypes, boost::mpl::back_inserter<boost::mpl::vector<> > >::type ZippedTypesVector;
|
---|
65 |
|
---|
66 | typedef detail::types_to_size_type<Types0>::type Size0;
|
---|
67 | Size0 size0;
|
---|
68 |
|
---|
69 | typedef detail::types_to_size_type<Types1>::type Size1;
|
---|
70 | Size1 size1;
|
---|
71 |
|
---|
72 | typedef detail::types_to_size_type<ZippedTypes>::type ZippedSizeType;
|
---|
73 | ZippedSizeType zippedSize;
|
---|
74 |
|
---|
75 | typedef boost::mpl::range_c<int, 0, boost::mpl::size<Types0>::type::value> IndexRange;
|
---|
76 |
|
---|
77 | boost::mpl::for_each<IndexRange>(detail::copy_size<Types0, Size0,
|
---|
78 | ZippedTypesVector, ZippedSizeType>(size0, zippedSize));
|
---|
79 | }
|
---|