是的,根据
[temp.arg.template]/2
:
与主类模板或主
变量模板
在实例化基于模板参数的专门化时,将考虑。。。
以及
[temp.expl.spec]/7
... 放置
部分专门化声明
类模板,
变量模板
、非模板类的成员类模板、非模板类的静态数据成员模板、类模板的成员类模板等。。。
它也在报告中提到
[constraints.namespace.std]/3
:
C++程序的行为如果声明了显式的或未定义的,则是未定义的。
部分专业化
任何标准库
变量模板
,除非该变量模板的规范明确允许。
template <int x, int y>
constexpr int foo = -1;
template <>
constexpr float foo<1, 0> = 1.0;
template <int x>
constexpr double foo<1, x> = 1.1;
int main()
{
static_assert(foo<0, 0> == -1, "");
static_assert(foo<0, 1> == -1, "");
static_assert(foo<1, 0> == 1.0, "");
static_assert(foo<1, 1> == 1.1, "");
}
https://godbolt.org/z/R1c1zo