如何在C ++ 0x中使用`>>>`lexed? [英] How is `>>>` lexed in C++0x?

查看:123
本文介绍了如何在C ++ 0x中使用`>>>`lexed?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

>>> 被命名为>> > 。但是,如果第一个> 关闭模板参数列表,如果结果等价于> > > > >< / code>?

>>> is lexed as >> >. But what happens if the first > closes a template argument list, should the result be equivalent to > > > or > >>?

在以下代码中无关紧要:

It does matter in the following code:

template<class T> struct X { };

void operator >>(const X<int>&, int) { }

int main() {
    *new X<int>>> 1;
}


推荐答案


同样,第一个非嵌套>>被视为两个连续但不同的标记

Similarly, the first non-nested >> is treated as two consecutive but distinct > tokens

它不能unlex令牌和relex。所以这将是一个> > > 。注意,C ++实现的输入首先被引入到预处理令牌中,然后这些令牌被转换为C ++令牌。所以首先你的输入是C ++令牌>> > ,那么C ++解析器将这些更改为> > >

It cannot unlex tokens and relex. So this will be a > > >. Note that the input to a C++ implementation is first lexed into preprocessing tokens, and then those tokens are converted into C++ tokens. So first your input are the C++ tokens >> >, then the C++ parser changes these to > > >.


每个预处理令牌都会转换为令牌。 (2.7)。所得到的令牌在语法和语义上被分析和翻译为翻译单元。 [注意:分析和翻译令牌的过程偶尔可能导致一个令牌被其他令牌的序列(14.2)替换。 - end note]

Each preprocessing token is converted into a token. (2.7). The resulting tokens are syntactically and semantically analyzed and translated as a translation unit. [ Note: The process of analyzing and translating the tokens may occasionally result in one token being replaced by a sequence of other tokens (14.2). — end note ]

没有可能合并这两个结尾的 > 令牌。

There's no chance you could merge those two trailing > > tokens.

这篇关于如何在C ++ 0x中使用`&gt;&gt;&gt;`lexed?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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