哪些 IDE 和文本编辑器可以推断在 C++11 中使用 auto 关键字声明的变量类型 [英] Which IDEs and text editors can deduce type of variables declared using auto keyword in C++11

查看:28
本文介绍了哪些 IDE 和文本编辑器可以推断在 C++11 中使用 auto 关键字声明的变量类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

"几乎总是自动" 文章 Herb Sutter 列出了使用 auto 关键字声明变量的几个原因.

In "Almost always auto" article Herb Sutter lists several reasons for declaring variables using auto keyword.

他说实际的变量类型可以由 IDE 自动推导出,并通过将鼠标悬停在变量名称上来显示.

He says that actual variable type can be automatically deduced by IDE and shown by hovering over variable name.

我想知道目前哪些 IDE 和文本编辑器(或插件)支持自动"变量类型推导.

I would like to know which IDEs and text editors (or plugins) currently support "auto" variable type deduction.

来自答案的 IDE 列表:

  • Visual Studio 201x
  • 日蚀
  • Qt Creator 2.7.0
  • KDevelop 4.5.1

文本编辑器

Vim、Emacs、Sublime Text 等怎么样 - 有支持类型推导的插件吗?

What about Vim, Emacs, Sublime Text, etc. - are there plugins which supports type deduction?

推荐答案

Visual Studio 2010、Visual Studio 2012 和 Visual Studio 2013 支持对使用 auto 关键字声明的变量进行类型推导.这既适用于 IntelliSense 工具提示,也适用于自动完成建议.

Visual Studio 2010, Visual Studio 2012, and Visual Studio 2013 support type deduction for variables declared with the auto keyword. This applies both to the IntelliSense tooltips as well as auto-complete suggestions.

从 Visual Studio 2010 开始,C++ IntelliSense 支持完全重新设计(参见 重建智能感知).IntelliSense 现在由 Edison Design Group (EDG) C++ 编译器前端 驱动.无论 EDG 能做什么,您都会在 IntelliSense 中看到.

Starting with Visual Studio 2010 the C++ IntelliSense support was completely reworked (see Rebuilding Intellisense). IntelliSense is now driven by the Edison Design Group (EDG) C++ compiler frontend. Whatever EDG can do you will see reflected in IntelliSense.

请注意,IntelliSense 工具提示将显示 auto 变量的基础类型.它不会再次处理树并用适当的 typedef 替换部分.在 Visual Studio 2012 上,以下代码

Note that IntelliSense tooltips will display the underlying type for auto variables. It will not work up the tree again and replace portions with appropriate typedefs. On Visual Studio 2012 the following code

std::string str;

std::string::iterator i1 = str.begin();
auto i2 = str.begin();

将迭代器显示为

std::basic_string<char,std::char_traits<char>,std::allocator<char> >::iterator i1

std::_String_iterator<std::_String_val<std::_String_base_types<char,std::allocator<char> >::_Val_types>::_Myt> i2

鉴于我很乐意不同意 Herb Sutter 的评估,即 IDE 足以在您需要时推断出类型.auto 在健壮性、正确性和灵活性方面非常出色,但它肯定无法满足开发人员在大型代码库上工作的需求.

Given that I would happily disagree with Herb Sutter on his assessment that an IDE is enough to deduce a type when you need it. auto is great with respect to robustness, correctness and flexibility, but it surely fails to meet a developer's needs working on a large code base.

这篇关于哪些 IDE 和文本编辑器可以推断在 C++11 中使用 auto 关键字声明的变量类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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