如果包是空的,是否对可变参数包类型执行替换? [英] Is substitution performed on a variadic parameter pack type if the pack is empty?

查看:173
本文介绍了如果包是空的,是否对可变参数包类型执行替换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请考虑以下程序:

#include <type_traits>

enum class dummy {};
template <typename T>
using EnableIf = typename std::enable_if<T::value, dummy>::type;
template <typename T>
using DisableIf = typename std::enable_if<!T::value, dummy>::type;

template <typename T>
struct dependent_true_type : std::true_type {};

template <typename T,
          EnableIf<dependent_true_type<T>>...>
std::true_type f();
template <typename T,
          DisableIf<dependent_true_type<T>>...>
std::false_type f();

static_assert(decltype(f<int>())::value, "");

int main() {}

GCC 4.7 glady接受此程序。我最近的clang 3.1 build声称对 f 的调用是不明确的。

GCC 4.7 glady accepts this program. My recent clang 3.1 build claims the call to f is ambiguous.

test.c++:22:24: fatal error: call to 'f' is ambiguous
static_assert(decltype(f<int>())::value, "");
                       ^~~~~~
test.c++:17:16: note: candidate function [with T = int, $1 = <>]
std::true_type f();
               ^
test.c++:20:17: note: candidate function [with T = int, $1 = <>]
std::false_type f();
                ^
1 error generated.

如果我写 f

看来ang不考虑参数包的类型,当包为空时,它从候选集。 GCC似乎在参数包类型上执行替换,即使包是空的,并且由于所述替换对于一个重载而失败,因此没有歧义。

It seems clang does not consider the type of the parameter pack when the pack is empty, which leads to not removing it from the candidate set. GCC seems to perform substitution on the parameter pack type even if the pack is empty, and since said substitution fails for one overload, there is no ambiguity.

是正确的?

推荐答案

我相信我找到了相关的标准。 §14.8.2p7说:

I believe I have found the relevant piece of standardese. §14.8.2p7 says:


替换出现在函数类型和模板参数声明中使用的所有类型和表达式中。 / p>

The substitution occurs in all types and expressions that are used in the function type and in template parameter declarations.

由于 EnableIf< dependent_true_type< T>> 声明,替换,这是 a中的错误

Since EnableIf<dependent_true_type<T>> is used in a template parameter declaration, substitution should occur and this is a bug in clang.

这篇关于如果包是空的,是否对可变参数包类型执行替换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆