有没有一种方法可以在模板参数列表中使用type_traits更改类型?

时间:2018-10-31 22:10:20

标签: c++11 templates generic-programming

template
<
    template <typename, typename, typename>
        class storage_t,
    typename _Tp = storage::unknown_type,
    typename is_allocated = std::false_type
>
struct Example_Buffer:
    public Buffer<storage_t, _Tp, is_allocated> { ... };

在这段代码中,如果_Tp有一个引用,我想删除该引用。我不想使用typename = std::enable_if_t<std::is_reference_v<_Tp>>,因为如果_Tp是引用,我确实希望程序进行编译,但是在这种情况下,我想将其删除。我想到了一个解决方案,但这似乎并不理想:

template
<
   template <typename, typename, typename>
        class storage_t,
    typename _Tp = storage::unknown_type,
    typename is_allocated = std::false_type,
    typename _Tp2 = std::remove_reference_t<_Tp>
>
struct Example_Buffer { ... };

编辑:这似乎并不理想,因为感觉类型_Tp2是不必要的,可以避免。我可能错了;如果是这样,请告诉我。

有更好的方法吗?随时问我是否需要详细说明。

编辑:我实际上忘了提及当前的解决方案:

struct Example_Buffer
    : public Buffer<storage_t, std::remove_reference_t<_Tp>, is_allocated { ... };

但是,我可能想在_Tp结构中使用Example_Buffer,所以也不理想。

0 个答案:

没有答案