小编And*_*ita的帖子

具有可变参数模板类的SFINAE?

我似乎找不到使用SFINAE和可变参数模板类的好解决方案.

假设我有一个不太喜欢引用的可变参数模板对象:

template<typename... Args>
class NoRef
{
    //if any of Args... is a reference, this class will break
    //for example:
    std::tuple<std::unique_ptr<Args>...> uptrs;
};
Run Code Online (Sandbox Code Playgroud)

还有一个类可以方便地检查参数包是否包含引用:

template<typename T, typename... Other>
struct RefCheck
{
    static const bool value = std::is_reference<T>::value || RefCheck<Other...>::value;
};
template<typename T>
struct RefCheck<T>
{
    static const bool value = std::is_reference<T>::value;
};
Run Code Online (Sandbox Code Playgroud)

在arg包中存在引用的情况下,如何使用它来专门化NoRef?

c++ sfinae variadic-templates

6
推荐指数
2
解决办法
1396
查看次数

标签 统计

c++ ×1

sfinae ×1

variadic-templates ×1