Eric Niebler writes:
On 3/20/2015 11:44 AM, Louis Dionne wrote:
As a simple curiosity, here's how this could be implemented with Hana:
<snip>
And using Meta:
[...]
Eric, abstracting the sort into an `indexed_sort` (meta)function
is a great idea. Here's an updated version:
------------------------------------------------------------------------------
#include
#include
#include
#include
#include
using namespace boost::hana;
using namespace boost::hana::literals;
auto indexed_sort = [](auto list, auto predicate) {
auto indexed_list = zip(list, to<Tuple>(range(0_c, size(list))));
auto sorted = sort_by(predicate, indexed_list);
return make_pair(transform(sorted, head), transform(sorted, last));
};
int main() {
auto types = tuple_t;
auto sorted = indexed_sort(types, [](auto t, auto u) {
return sizeof_(t[0_c]) < sizeof_(u[0_c]);
});
using Tup = decltype(unpack(first(sorted), template_<_tuple>))::type;
auto indices = second(sorted);
Tup tup;
char(&a)[3] = tup[indices[0_c]];
char(&b)[2] = tup[indices[1_c]];
char(&c)[5] = tup[indices[2_c]];
}
------------------------------------------------------------------------------
FWIW, these indices don't seem all that useful to me. What exactly was
the desired behavior?
No idea :-)
Louis