|
Boost : |
Subject: Re: [boost] [TypeSort] Automatic type sorting
From: Eric Niebler (eniebler_at_[hidden])
Date: 2015-03-21 21:31:51
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:
#include <tuple>
#include <meta/meta.hpp>
using namespace meta;
namespace l = lazy;
template<typename List>
using indexed_sort_ = sort<zip<
list<List,as_list<make_index_sequence<List::size()>>>>,
lambda<_a,_b,l::less<l::sizeof_<l::first<_a>>,
l::sizeof_<l::first<_b>>>>>;
template<typename List>
using indexed_sort =
pair<transform<indexed_sort_<List>,quote<first>>,
transform<indexed_sort_<List>,quote<second>>>;
int main()
{
using P =
indexed_sort<list<char[4],char[2],char[1],char[5],char[3]>>;
using Tup = apply_list<quote<std::tuple>, first<P>>;
using Idx = second<P>;
// list<int_<2>,int_<1>,int_<4>,int_<0>,int_<3>>
Tup tup; // std::tuple<char[1],char[2],...char[5]>
char(&a)[3] = std::get<at_c<Idx, 0>::value>(tup);
char(&b)[2] = std::get<at_c<Idx, 1>::value>(tup);
char(&c)[5] = std::get<at_c<Idx, 2>::value>(tup);
}
FWIW, these indices don't seem all that useful to me. What exactly was
the desired behavior?
-- Eric Niebler Boost.org http://www.boost.org
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk