VS2013 Intellisense不了解decltype [英] VS2013 Intellisense doesn't understand decltype

查看:186
本文介绍了VS2013 Intellisense不了解decltype的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否存在一个修补程序(官方或非官方),以使IntelliSense停止报告每次使用decltype作为语法错误的情况?它可以很好地编译,所以我知道支持decltype,但是看到红色的花样到处都是非常令人分心的事情,这使得在代码中查找 actual 错误变得更加困难.每次编译都会给我列出数百个非错误的列表-对于代码库中每次decltype的使用,基本上至少3个错误,例如:

Is there a patch out there (official or unofficial) to get IntelliSense to stop reporting every use of decltype as a syntax error? It compiles fine, so I know decltype is supported, but it's very distracting seeing red squiggles everywhere and makes it much harder to find actual errors in the code. Every compile gives me a list of hundreds of non-errors - basically at least 3 for every use of decltype in the code base, e.g.:

std::for_each(std::begin(list), std::end(list), [](const decltype(list)::value_type& item)
{
    <do stuff with item>
});

将产生以下(非)错误:

will produce the following (non) errors:

IntelliSense: global-scope qualifier (leading '::') is not allowed
IntelliSense: expected a ')'
IntelliSense: identifier "item" is undefined

目前还不能升级到VS2015. (我怀疑我能否说服该公司花钱升级每台计算机,而仅升级其中一些会导致向后兼容性问题.)

Upgrading to VS2015 is not an option at this point. (I doubt I could convince the company to shell out to upgrade every computer, and upgrading only some of them would lead to backwards compatibility issues.)

就我个人而言,我不希望完全不使用decltype,直到我们得到一个完全支持decltype的IDE(我不知道您实际上 需要它),但是我不这样做.我想我也不能说服所有人.我只是想消除所有这些假错误,以便我能找到真正的错误而不必研究成千上万的假阳性.

Personally, I'd prefer not to use decltype at all until we get an IDE that fully supports it (there's nowhere I know of that you actually need it), but I don't think I can convince everybody of that either. I just want to make all those fake errors go away so that I can find the real ones without poring over thousands of false-positives.

推荐答案

给出帮助模板别名

template <typename T> using id = T;

通过编写id<decltype(list)>::value_type可以避免Intellisense错误,同时仍然保持代码完全有效.

you can avoid the Intellisense errors, while still keeping the code perfectly valid, by writing id<decltype(list)>::value_type where you would otherwise have written decltype(list)::value_type.

根据decltype之后紧跟::的频率,您可能希望创建一个简单的宏,如下所示:

Depending on how often decltype is immediately followed by ::, you may want to create a macro as simple as:

#define DECLTYPE(x) id<decltype(x)>

这篇关于VS2013 Intellisense不了解decltype的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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