小编Ste*_*ina的帖子

Variadic模板类型演绎

我看到了这篇很棒的文章:http://pdimov.com/cpp2/simple_cxx11_metaprogramming.html

在以下代码中:

template<class A, template<class...> class B> struct mp_rename_impl;

template<template<class...> class C, class... T, template<class...> class B>
struct mp_rename_impl<C<T...>, B>
{
    using type = B<T...>;
};

template<class A, template<class...> class B>
using mp_rename = typename mp_rename_impl<A, B>::type;

//...
mp_rename<mp_list<int, float, void*>, std::tuple>; // -> std::tuple<int, float, void*>
                                                   // T... will be deduced as int, float, void*
Run Code Online (Sandbox Code Playgroud)

为什么C被推导为mp_list(而不是mp_list <int,float,void*>)和T ...作为int,float,void*

我认为诀窍是模板特化部分: struct mp_rename_impl <C <T ...>,B>,但我很难理解为什么

c++ templates metaprogramming c++11

6
推荐指数
1
解决办法
201
查看次数

标签 统计

c++ ×1

c++11 ×1

metaprogramming ×1

templates ×1