Skip to content

Latest commit

 

History

History
55 lines (45 loc) · 1.41 KB

Sort.md

File metadata and controls

55 lines (45 loc) · 1.41 KB

<CppML/Algorithm/Sort.hpp>

Sort

template <typename Compare, typename Pipe = ml::ToList>
struct Sort {
  template <typename ...Ts>
  using f = /* .... */;
};

Sort<Compare, Pipe>

Sort<Compare, Pipe> is a metafunction that passes to Pipe a parameter pack Us... which is such a reordering of the parameter pack Ts..., that is sorted by the Compare metafunction. Pipe defaults to ml::ToList.

f:: Ts... -> Us... >-> Pipe

Compare

Compare must be a metafunction acting on two types and returning ml::Bool<truth_value>.

f:: (T, U) -> ml::Bool<truth_value>

Example

We sort types by their alignment.

using T = ml::f<
                ml::Sort<
                    ml::Map<
                            ml::AlignOf<>,
                            ml::Greater<>>>,
                int, double, char, long>;
static_assert(
              std::is_same_v<
                  T,
                  ml::ListT<
                    long, double, int, char>>);

NOTE that

ml::Map<
        ml::AlignOf<>, // maps each element by taking its alignment
        ml::Greater<>>      // and pipes the resulting parameter pack into greater

is a metafunction of type

(T, U) -> (AlignOf(T), AligmentOf(U)) >-> ml::Greater

and is as such a valid compare metafunction. See ml::Map.