gpt4 book ai didi

c++ - 为什么未使用的部分特化没有错误?

转载 作者:行者123 更新时间:2023-11-30 04:01:53 24 4
gpt4 key购买 nike

Foo 的特化永远不会被使用; Clang 会发出警告,而 GCC 不会。

template <typename>
struct Foo { static const int value = 0; };

template <template <typename...> class C, typename ...Ts>
struct Foo<C<Ts..., int>> { static const int value = 1; };

为什么这不会导致错误?

下面的代码演示了这一点:

template <typename...>
struct Bar {};

static_assert(!Foo<Bar<char,double,int>>::value,"");

最佳答案

定义某物而不使用它并不是错误。如果是这样,在每个程序中你 #include<vector> 你将不得不使用 vector<bool>

关于c++ - 为什么未使用的部分特化没有错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25493828/

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