Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which IDEs and text editors can deduce type of variables declared using auto keyword in C++11

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

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

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

Edit:

List of IDEs from answers:

  • Visual Studio 201x
  • Eclipse
  • Qt Creator 2.7.0
  • KDevelop 4.5.1

Text editors

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

like image 412
Johny Avatar asked Oct 27 '13 23:10

Johny


1 Answers

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.

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.

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();

will display the iterators as

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

and

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

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.

like image 112
IInspectable Avatar answered Oct 06 '22 00:10

IInspectable