使用boost::mp11::mp_nth_element_q实现的测试程序
boost::mp11是一个元编程库,其中包含了许多方便的元算法。其中包括mp_nth_element_q,用于找到第n个元素。
mp_nth_element_q的用法非常简单,它只需要一个序列和一个整数作为模板参数。下面我们来看一个具体的例子:
#include <boost/mp11.hpp>
#include <iostream>
#include <type_traits>
#include <tuple>
int main()
{
using boost::mp11::mp_list;
using boost::mp11::mp_size_t;
// 定义一个 tuple
auto my_tuple = std::make_tuple(1, 2.0, "hello");
// 将 tuple 转换成 mp_list
using my_list = boost::mp11::mp_transform<std::decay_t, decltype(my_tuple)>;
// 打印 my_list,并打印出其中第 1 个元素的类型
std::cout << boost::mp11::mp_size<my_list>::value << ": " << boost::m