gpt4 book ai didi

c++ - 部分特化类型特征时如何使用 std::decay?

转载 作者:太空狗 更新时间:2023-10-29 20:03:26 25 4
gpt4 key购买 nike

我创建这些类型特征是为了确定类型是否是动态容器,但最近在对 vector 的引用未返回 true 时遇到了困惑。

template<typename T>
struct is_dynamic_container
{
static const bool value = false;
};

template<typename T , typename Alloc>
struct is_dynamic_container<std::vector<T , Alloc>>
{
static const bool value = true;
};

我想我需要使用 std::decay ,但我无法确定是否可以像这样而不是在调用站点完成。

template<typename T , typename Alloc>
struct is_dynamic_container<std::decay<std::vector<T , Alloc>>::type>
{
static const bool value = true;
};

^^这行不通。

我只想能够写is_dynamic_container<std::vector<int>&>而不是 is_dynamic_container<std::decay<std::vector<int>&>::type> .这可能吗?

最佳答案

template<class T>
using is_dynamic_container_with_decay = is_dynamic_container<std::decay_t<T>>;

关于c++ - 部分特化类型特征时如何使用 std::decay?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29587258/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com