Export (0) Print
Expand All

What's New for Visual C++ in Visual Studio 2012

This document introduces new and enhanced features in Visual C++ in Visual Studio 2012.

For information about other additions in Visual Studio 2012, see What's New in Visual Studio 2012.

Note Note

For information about integrated development environment (IDE) features for developers who are creating Windows Store apps, see Develop Windows Store apps using Visual Studio 2012.

  • Support for new STL headers: <atomic>, <chrono>, <condition_variable>, <filesystem>, <future>, <mutex>, <ratio>, and <thread>.

  • To optimize memory resource usage, containers are now smaller. For example, in x86 release mode with default settings, std::vector has shrunk from 16 bytes in Visual Studio 2010 to 12 bytes in Visual Studio 2012, and std::map has shrunk from 16 bytes in Visual Studio 2010 to 8 bytes in Visual Studio 2012.

  • As permitted but not required by the C++11 Standard, SCARY iterators have been implemented. For more information, see the PDF document SCARY Iterator Assignment and Initialization.

  • Range-based for loops. You can write more robust loops that work with arrays, STL containers, and Windows Runtime collections in the form for ( for-range-declaration : expression ). This is part of the Core Language support. For more information, see Range-based for Statement (C++).

  • Stateless lambdas, which are blocks of code that begin with an empty lambda introducer [] and capture no local variables, are now implicitly convertible to function pointers as required by the C++11 Standard. For more information, see Lambda Expressions in C++.

  • Scoped enumerations support. The C++ enum class enum-key is now supported. The following code demonstrates how this enum-key differs from previous enum behavior.

    enum class Element { Hydrogen, Helium, Lithium, Beryllium };
    void func1(Element e);
    func1(Hydrogen); // error C2065: 'Hydrogen' : undeclared identifier
    func1(Element::Helium); // OK
    

  • Auto-vectorizer. The compiler analyzes loops in your code and, where possible, emits instructions that use the vector registers and instructions that are present in all modern processors. This makes the loops run faster. (The processor instructions are known as SSE, for Streaming SIMD Extensions). You do not have to enable or request this optimization because it is applied automatically.

  • Auto-parallelizer. The compiler can analyze loops in your code and emit instructions that spread the calculations across multiple cores or processors. This can make the loops run faster. You must request this optimization because it is not enabled by default. In many cases, it helps to include a #pragma loop(hint_parallel(N)) in your code immediately before the loops that you want parallelized.

    The auto-vectorizer and auto-parallelizer can work together so that calculations are spread across multiple cores and the code on each core uses its vector registers. For more information, see Auto-Parallelization and Auto-Vectorization.

  • Target Windows XP when you build your C++ code.

    You can use the Visual C++ compiler and libraries to target Windows XP and Windows Server 2003. For more information, see Configuring C++ 11 Programs for Windows XP.

C++ AMP accelerates the execution of your C++ code by taking advantage of the data-parallel hardware that's ordinarily present as a GPU on a discrete graphics card. The C++ AMP programming model includes multidimensional arrays, indexing, memory transfer, tiling, and a mathematical function library. By using C++ AMP language extensions and compiler restrictions, you can control how data is moved from the CPU to the GPU and back. For more information, see C++ AMP (C++ Accelerated Massive Parallelism).

Debugging. The debugging experience for apps that use C++ AMP to target the GPU is just like debugging for other C++ apps. This includes the new parallel debugging additions that were mentioned earlier. See Debugging GPU Code.

Profiling. There is now profiling support for GPU activity that's based on C++ AMP and other Direct3D-based programming models. See GPU Activity Graph.

With hardware moving to multi-core and many-core architectures, developers can no longer rely on ever-increasing clock speeds from single-cores. The parallel programming support in the Concurrency Runtime enables developers to take advantage of these new architectures.

In Visual Studio 2010, powerful C++ parallelization libraries such as the Parallel Patterns Library were introduced, together with features to take advantage of concurrency by expressing sophisticated dataflow pipelines. In Visual Studio 2012, these libraries have been extended to provide better performance, more control, and richer support for the parallel patterns that developers need most. The breadth of the offering now includes:

  • A rich task-based programming model that supports asynchrony and continuations. For more information, see Task Parallelism (Concurrency Runtime).

  • Parallel Algorithms , which support fork-join parallelism (parallel_for, parallel_for with affinity, parallel_for_each, parallel_sort, parallel_reduce, parallel_transform).

  • Concurrency-safe containers, which provide thread-safe versions of std data structures such as priority_queue, queue, vector, and map.

  • The Asynchronous Agents Library, which developers can use to express dataflow pipelines that naturally decompose into concurrent units.

  • A customizable scheduler and resource manager to facilitate the smooth composition of the patterns in this list. See Task Scheduler (Concurrency Runtime).

In addition to the Parallel Tasks window and Parallel Stacks window, Visual Studio 2012 offers a new Parallel Watch window so that you can examine the values of an expression across all threads and processes, and perform sorting and filtering on the result. You can also use your own visualizers to extend the window, and you can take advantage of the new multi-process support across all tool windows. For more information, see How to: Use the Parallel Watch Window.

The tools in the Visual Studio IDE have significant improvements to help you be more productive when you code in C++. For more information about IDE enhancements, see Product Highlights for Visual Studio 2012.

  • Visual Studio Templates support. You can now use the Visual Studio Templates technology to author C++ project and item templates.

  • Asynchronous Solution Load. Projects are now loaded asynchronously—the key parts of the solution first—so that you can start working faster.

  • Automated deployment for remote debugging. Deployment of files for remote debugging in Visual C++ has been simplified. The Deploy option on the project context menu automatically copies to the remote computer the files that are specified in the debugging configuration properties. Copying files manually to the remote computer is no longer required. For more information, see Remote Debugging of a Project Built Locally.

  • C++/CLI IntelliSense. C++/CLI now has full IntelliSense support. IntelliSense features such as Quick Info, Parameter Help, List Members, and Auto Completion now work for C++/CLI. In addition, the other IntelliSense and IDE enhancements listed in this document also work for C++/CLI.

  • Richer IntelliSense Tooltips. C++ IntelliSense Quick Info tooltips now show richer XML documentation comments style information. If you are using an API from a library—for example, C++ AMP—that has XML documentation comments, then the IntelliSense tooltip shows more information than just the declaration. Also, if your code has the XML documentation comments, IntelliSense tooltips will show the richer information.

  • C++ Code Constructs. Skeleton code is available for switch, if-else, for loop, and other basic code constructs, in the List Members drop-down list. Select a piece of code from the list to insert it into your code and then fill in the required logic. You can also create your own custom pieces of code for use in the editor. For more information, see Code Snippets.

  • List Members Enhancements. The List Members drop-down list appears automatically as you type code into the code editor. Results are filtered, so that only relevant members are displayed as you type. You can control the kind of filtering logic that's used by the Member List—in the Options dialog box under Text Editor, C/C++, Advanced. For more information, see Using IntelliSense.

  • Semantic Colorization. Types, enumerations, macros, and other C++ tokens now have colorization by default. For more information, see Writing Code in the Code and Text Editor.

  • Reference Highlighting. Selecting a symbol now highlights all instances of the symbol in the current file. Press Ctrl+Shift+Up Arrow or Ctrl+Shift+Down Arrow to move among the highlighted references. You can turn this feature off in the Options dialog box, under Text Editor, C/C++, Advanced.

Static analysis for C++ has been updated to provide richer error context information, more analysis rules, and better analysis results. In the new Code Analysis window, you can filter messages by keyword, project, and severity. When you select a message in the window, the line in the code where the message was triggered is highlighted in the code editor. For certain C++ warnings, the message lists source lines that show the execution path that leads to the warning; decision points and the reasons for taking that specific path are highlighted.

Code analysis is included in most editions of Visual Studio 2012. In the Professional, Premium, and Ultimate editions, all rules are included. In the Express editions for Windows 8 and Windows Phone, just the most critical warnings are included. Code analysis is not included in the Express edition for Web.

Here are some other code analysis enhancements:

  • New concurrency warnings help you avoid concurrency bugs by making sure that you are using the correct locking disciplines in multithreaded C/C++ programs. The analyzer detects potential race conditions, lock order inversions, caller/callee locking contract violations, mismatched synchronization operations, and other concurrency bugs.

  • You can specify the C++ rules that you want to apply to code analysis runs by using rule sets.

  • In the Code Analysis window, you can insert into the source code a pragma that suppresses a selected warning.

  • You can enhance the accuracy and completeness of static code analysis by using the new version of the Microsoft source-code annotation language (SAL) to describe how a function uses its parameters, the assumptions that it makes about them, and the guarantees that it makes when it finishes.

  • Support for 64bit C++ projects.

For more information about how to improve the quality of your code, see Analyzing Application Quality by Using Code Analysis Tools.

Use the new C++ unit test framework in Visual Studio to write C++ unit tests. Add a new unit test project to your existing C++ solution by locating the C++ Unit Test Project template under the Visual C++ category in the New Project dialog box. Start writing your unit tests in the generated TEST_METHOD code stub in the Unittest1.cpp file. When the test code is written, build the solution. When you want to run the tests, open a Unit Test Explorer window by choosing View, Other Windows, Unit Test Explorer, and then, on the shortcut menu for the test case you want, choose Run selected test. After the test run finishes, you can view test results and additional stack trace information in the same window. See Verifying Code by Using Unit Tests and Creating and running unit tests on a Windows Store app.

To understand your code better, you can now generate dependency graphs for the binary, class, namespace, and include files in a solution. On the menu bar, choose Architecture, Generate Dependency Graph, and then For Solution or For Include File to generate a dependency graph. When the graph generation is complete, you can explore it by expanding each node, learn dependency relationships by moving between nodes, and browse source code by choosing View Content on the shortcut menu for a node. To generate a dependency graph for include files, on the shortcut menu for a *.cpp source code file or *.h header file, choose Generate Graph of Include Files. See Visualize Code Dependencies on Dependency Graphs.

By using the Architecture Explorer, you can explore the assets in your C++ solution, projects, or files. On the menu bar, choose Architecture, Windows, Architecture Explorer. You can select a node you are interested in, for example, Class View. In this case, the right side of the tool window is expanded with a list of namespaces. If you select a namespace, a new column shows a list of the classes, structs, and enums in this namespace. You can continue to explore these assets, or go back to the column on the far left to start another query. See Find Code with Architecture Explorer.

Code coverage has been updated to dynamically instrument binaries at runtime. This lowers the configuration overhead and provides better performance. You can also collect code-coverage data from unit tests for C++ app. For more information about how to create and run unit tests, see the Unit Test Framework section of this document. When you have created C++ unit tests, you can use Unit Test Explorer to discover tests in your solution. To run the unit tests and collect code coverage data for them, in Unit Test Explorer, choose Analyze Code Coverage. You can examine the code coverage results in the Code Coverage Results window—on the menu bar, choose Test, Windows, Code Coverage Results. See Using Code Coverage to Determine How Much Code is being Tested.

Community Additions

ADD
Show:
© 2014 Microsoft