Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/137.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 了解模板函数调用中的嵌套>>_C++_Templates - Fatal编程技术网

C++ 了解模板函数调用中的嵌套>>

C++ 了解模板函数调用中的嵌套>>,c++,templates,C++,Templates,考虑以下代码: #include <iostream> using std::cout; using std::endl; struct A { constexpr int operator[](int a) { return a; } constexpr operator int() { return 1; } } a; template <int a> int foo() {

考虑以下代码:

#include <iostream>

using std::cout;
using std::endl;

struct A
{
    constexpr int operator[](int a)
    {
        return a;
    }

    constexpr operator int()
    {
        return 1;
    }
} a;

template <int a>
int foo()
{
    return a;
};

int main(){ cout << foo<a[4 >> 1]>() << endl; }
这是标准的N4286::14.2/3[临时名称]

类似地,第一个非嵌套>>被视为两个连续但 distinct>标记,其中第一个标记作为 模板参数列表并完成模板id

其中,嵌套的定义包含动态\u转换、静态\u转换的类型id, 重新解释或const_cast,或包含 后续模板id的模板参数被视为嵌套的 为了本说明的目的


在我的例子中>>是非嵌套的,因此第一个脚注137不是嵌套的定义;它澄清了在这些情况下,>被认为是嵌套的,而不仅仅是那些>是嵌套的。而且,@T.C.这个问题已经存在了将近9年,它仍然处于打开状态。那么,根据目前的工作草案,我的问题目前无法解决,是吗?顺便说一句,clang和g++都接受问题中的代码