当前位置:网站首页>Implementation of template metaprogramming boost:: MPL

Implementation of template metaprogramming boost:: MPL

2021-01-23 20:06:45 ink19

Preface

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 .

Use perception

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 .

Realization

Source code : https://github.com/ink19/boost_mpl_sort

The original blog :https://www.cnblogs.com/ink19/p/boost_mpl_sort.html

版权声明
本文为[ink19]所创,转载请带上原文链接,感谢
https://chowdera.com/2021/01/20210123200601067b.html

随机推荐