After finishing the sorting of the first three template metaprogramming , Began to Boost Of MPL Ku is interested in , So we use MPL Re implement the three sorting algorithms , Selection sort 、 Quick sort 、 Heap sort .
It's about the same time as before , Heap sorting takes most of my time . The simplest is to choose the sort , It's implemented with just one class .
Boost::MPL It greatly simplifies the difficulty of metaprogramming , It implements most of the algorithms , Especially vectors （vector） The operation of , Imitation std::vector, There are also corresponding iteration types . There are two control structures , Judgment and cycle , The judgment structure is similar to the previous one . But the cycle structure is very different , Its realization is the folding which is commonly used in functional programming （fold）.
Function calls are more regular , Basically, multiple inputs correspond to one output . The way to use it is
typedef typename boost::mpl::func<argv1, argv2>::type output_type;
All structures have
::type, If it's a basic type , The current value is returned , So when using the branch structure, you can use the lazy loading function freely .
Source code ： https://github.com/ink19/boost_mpl_sort
The original blog ：https://www.cnblogs.com/ink19/p/boost_mpl_sort.html