That's actually very useful! However a less complicated interface would definitely be more appreciated! Maybe some wrapper functions or macros would do the trick.
Στις 5:16 μ.μ. Παρασκευή, 20 Μαρτίου 2015, ο/η Mathias Gaunard έγραψε:
On 20/03/2015 17:49, costis glynos wrote:
You also need to use Boost.Fusion to make it into a tuple at the end,
since this is what you want.
Here is an example:
#include
#include
#include
#include
#include
#include <iostream>
int main()
{
namespace mpl = boost::mpl;
namespace fusion = boost::fusion;
typedef mpl::vector types;
typedef mpl::sortmpl::_1
, mpl::sizeof_mpl::_2
>
>::type sorted_types;
typedef fusion::result_of::as_vector::type tuple;
tuple t;
std::cout << sizeof(t) << std::endl; // 8 instead of 12
}
This appears to work.
That's fantastic! Thank you for your recommendation.
You probably need to be able to access the final tuple with the original
indices though, which is a bit more involved.
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include <iostream>
int main()
{
namespace mpl = boost::mpl;
namespace fusion = boost::fusion;
typedef mpl::vector types;
typedef mpl::copy<
mpl::zip_view<
mpl::vector< types
, mpl::range_c
>
>
, mpl::back_inserter< mpl::vector0<> >
>::type indexes_types;
typedef mpl::sort<
indexes_types
, mpl::less< mpl::sizeof_< mpl::frontmpl::_1 >
, mpl::sizeof_< mpl::frontmpl::_2 >
>
>::type indexes_types_sorted;
typedef mpl::transform<
indexes_types_sorted
, mpl::frontmpl::_1
>::type sorted_types;
typedef mpl::transform<
indexes_types_sorted
, mpl::backmpl::_1
>::type sorted_indexes;
typedef fusion::result_of::as_vector::type tuple;
tuple t;
std::cout << sizeof( fusion::at_c::type::value>(t) ) << std::endl;
std::cout << sizeof( fusion::at_c::type::value>(t) ) << std::endl;
std::cout << sizeof( fusion::at_c::type::value>(t) ) << std::endl;
}
This could make an interesting addition to Boost.Fusion.
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost