For a Microsoft event we have been hired to do a full-day workshop about news in Visual Studio 2012 for C++ developers. My colleague Philipp Aumayr conducted the workshop. Here are the slides for his talk. More details including sample code can be found in our developer blog at http://www.software-architects.com
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Whats New in Visual Studio 2012 for C++ Developers
1. Philipp Aumayr
software architects gmbh
Web http://www.timecockpit.com
Mail philipp@timecockpit.com
Visual C++ 2012 Twitter @paumayr
Improvements over 2008
Saves the day.
2. Intro
DI Philipp Aumayr
Senior Developer @ software architects (time cockpit)
9-5 -> C#, 5->9 C++, 24/7 VS 2012
Twitter: @paumayr
Blog: http://www.timecockpit.com/devblog/
3. Motivation
Visual Studio 2012 improvements over 2008
New Shell
New Editor
Better Intellisense
Unit Testing
Code Coverage
Code Analysis
#include completion
Navigate To
Type visualizers
4. Motivation
C++11
New standard released August 12, 2011
Major overhaul
Bjarne Stroustrup: „C++11 feels like a new language“
Visual Studio 2012 has partial support
Is updated out-of-band (November CTP adds major language parts)
auto, decltype, range-based for loop
lambdas, explicit overrides, static_assert
nullptr, enum classes, move-semantics, variadic templates,
initializer_lists, delegating constructors,
explicit conversion operators
6. Motivation
Auto-vectorization
Auto-parallelization
C++ AMP
A lot to learn, but well worth the effort!
7. IDE Improvements
Multi-monitor support
Rewritten in WPF and MEF
Improved responsiveness
Intellisense works in the background
Asynchronous project loading
Editor Zooming
Navigate-To
Call Hierarchy
Demo
8. IDE Improvements
Preview tab
Pinned editor windows
Ctrl + Q / Search Menu
New Solution explorer
Scope to this
multiple views
Find within editor
Find all references
Demo
9. Test Framework
Supports writing unit tests for MSTest
Test adapters for other test frameworks are available
Gtest
xUnit++
Test Explorer Window
Grouping
Code Coverage
Demo
11. Type Visualizers (Natvis)
Allow customizable data representation in debugger
Replaces autoexp.dat
Easier to handle, more powerful
Create a natvis file
Place in either
%VSINSTALLDIR%Common7PackagesDebuggerVisualizers (requires admin access)
%USERPROFILE%My DocumentsVisual Studio 2012Visualizers
Or VS extension folders
Files are reloaded at every debugging session
No restart required when changing natvis files
12. Type Visualizers (Natvis)
Example natvis file
Allows
conditional strings, node expansions, item lists, tree items, synthetic items, etc.
15. C++ Styles (Question)
C with a C++ compiler?
C with classes / inheritance?
RAII, Exceptions, Smart pointer?
STL?
TMP?
16. auto
Automatically deduces type information
Very similar to „var‟ in c#
Reduces amount of typing required
Reference or Value?
Value by default, add & to make it a reference
Demo
17. decltype
Represents the type of the expression
decltype(2*3) -> int
decltype(a) -> type of a
Why?
Let types flow!
Demo
18. Range based for loop
New type of for loop
Iterates all members of a collection
Demo
19. Lambdas
Anonymous Functions
Allows logic to be placed where required
Can capture environment
General syntax:
[capture](parameters)->return-type{body}
represent by type std::function<>
20. Lambdas
Finally make STL algorithms useable
Reduces amount of (boilerplate-)code
No more functor classes!
21. Lambda Captures
A Lambda can capture environment
Allows the lambda to access and modify state
Capture kinds
- reference or value
- automatic or specific
Demo
22. override and final
Explicitly defines overrides
Compiler helps if no method to override is found
Helps with refactoring
Rename method in base class but not in derived -> derived method no longer overrides
Base class from third party!
Helps class design
Implementers of derived classes can more easily understand which methods to override
final can be used on classes to prevent being derived from
Demo
24. static_assert
Tests a software assertion at compile time
Especially useful for portable code
Assert size of specific structures (x86, x64 issues)
Check library versions
Used to be accomplished using the preprocessor
Demo
25. nullptr
0 / NULL used to indicate a null pointer
nullptr is of type nullptr_t
implicitly assignable to any pointer
not assignable to int etc.
26. enum classes
C++03 enums
Not type safe
Enums of different types can be compared (basically integers)
Storage type int
C++11 enum classes
Type is compared as well!
Underlying type can be chosen
30. Initializer lists (CTP)
Eases construction of non-POD types
Finalversion will provide initialize list constructors for
STL types
Binds {…} syntax to the std::initializer_list<T> type.
Current STL does not support it
Demo name == “class std::initializer_list<int>”
31. variadic templates (CTP)
Flexible number of template arguments
Usable for template writers
n-ary structures (tuples)
e.g. make_shared, make_tuple
Example: saveprint
Beware of dragons ;)
Demo
32. Move Semantics
C++03: many (temporary) class instances
Resulted in a lot of copying
Constructs to work around
Passing complex data structure from function
C++11: Move semantics
If the copied value is an rvalue reference, the move constructor is called
34. Move Semantics
Note: right-hand version is valid C++03 code!
But advanced programmers avoided it, due to the extra copy involved.
Now with C++11: Elegant AND Fast
Reconsider the patterns you are used to
All STL containers implement move semantics
Returning container was unavoidable? -> automatic performance improvement!
STL code will have fewer temporary objects
Demo
36. std::async
C++ 11 has built-in support for asynchrony
available through <future> header
std::async<T>(std::function) returns a future<T>
- Different launch policies (synchronous, asynchronous)
- can be waited on using wait() or get() to retrieve the result
Implemented in VC++ using PPL (parallel patterns
library)
- Highly scalable and performant
37. std::async
Not
every asynchronous operation is a thread / cpu
bound
Notably IO requests
User Input etc.
std::future<T> can be created from a std::promise<T>!
std::promise<T> acts as a provider for a future
Marshalls result between threads of execution
correct locking / etc.
Provides set_value / set_exception
39. Parallel Patterns Library
Based on ConcRT
Compatible to Intel Thread Building Blocks (TBB)
At least interface wise
Template Library for parallel programming
Abstracts concurrent workflows into tasks
Provides continuations (improvement over std::future<T>)
Demo
40. Auto Vectorization
Modern CPUs support SIMD
Single Instruction Multiple Data
Extensions such as SSE and AVX
Usually optimized for specifically using compiler intrinsics or inline assembler
Serial Vector
x = x1 + x2 xyzw = xyzw1 + xyzw2
y = y1 + y2
z = z1 + z2
w = w1 + w2
τ
41. Auto Vectorization
VC++ 2012 compiler has an auto-vectorizer (-Qvec)
Tries to automatically vectorize loops and operators
Enabled by default
Diagnosis output using /Qvec-report:2
Performance difference?
Depends.
Max 4x for SSE (128bit), 8x for AVX (256bit),
3x-4x typical
Demo (later with auto parallelization)
42. Auto-Parallelization
To utilize multiple cores, parallelization is used (MIMD)
Multiple-Instructions-Multiple-Data
VC++2012 has an auto-parallelizer
Can be hinted
#pragma loop(hint_parallel(N))
#pragma loop(ivdep)
Enabled using /Qpar
Diagnosis using /Qpar-report:2
Demo
43. C++ AMP
Open specification created by Microsoft
C++ for GPGPU
Massively Parallel / Vector programming
Based on top of DirectCompute (windows)
Clang / LLVM implementation using OpenCL is available
Provided by Intel (“Shevlin Park”)
One new keyword
Restricts the decorated function to a specific subset of c++
Template library for wrapping data structures
Datatransfer to/from GPU etc.
44. Why C++ AMP?
Directly available from the compiler
No additional SDK required
Can reuse types (vector2f e.g.)
Better debugging experience
compared to CUDA / OpenCL!
Makes C++ applicable to heterogeneous computing
A processor may consist of multiple cores of different flavor
More energy efficient (mobile!)
visual computing
image morphing
Augmented reality etc.
Demo
47. Code Analysis
Static analysis
Provides warnings at compile time
Additionally to /GS and /SDL
Detailed information on warning
48. Code Analysis
What does it check ?
Uninitialized Reads
HRESULT verification checks
Concurrency Warnings
Format string checks
Correct destructor calls (delete[] vs delete)
Redundant code checks
Many more: http://msdn.microsoft.com/en-us/library/a5b9aa09.aspx
Custom code can be annotated to aid code analysis
See http://msdn.microsoft.com/en-us/library/ms182032.aspx
Demo
50. Custom Snippets
.snippet is supported, same as C#
XML file describing a code snippet
Declare variables and use them in the snippet body
Very helpful for similar but not equivalent code
Demo
51. Debug View
Pin watch to source code
Add comments
Not only variables, but (most) expressions
View values from last debug session
Export / Import Data Tips
Makes it easier for debugging with multiple developers / on different machines
Demo
52. Parallel Stacks Window
New view for debugging
Better understanding of multi thread applications
54. Parallel Watch Window
Watch expressions in parallel
Especially useful in tight loops
Data races Expressions
Can freeze / thaw threads
Manually verify locking
Demo
Parallel Stacks
Parallel Tasks
Threads
Parallel Watch
55. Shortcuts
Shortcut Action Shortcut
Strg + , Navigate To Strg + Q Search Menu
F12 Go To Definition Strg + K, C Comment lines
Umschalt + F12 Find all references Strg + K, U Uncomment lines
Strg + - Navigate Backwards Strg + M, O Collapse To definition
Strg + Umschalt + - Navigate Forwards Strg +M, X Expand All Outlining
Strg + F Find in current file Strg +M, S Collapse Current Region
Strg + H Replace in current file Strg + M, E Expand Current Region
57. What‟s next?
It‟s a good century for C++ / native developers
Single thread performance isn‟t getting much better
memory latency / bandwidth is the bottleneck
Efficiency is becoming more important (mobile!)
There is a huge commitment towards C++
Google, Apple started a new compiler project a few years ago (Clang / LLVM)
ISO standard is evolving more quickly
C++ Standards Foundation (www.isocpp.org)
Google, Apple, Intel, Microsoft, ARM, IBM, HP, etc.
58. Upcoming Standards
Library in std:: for file system handling
based on boost.filesystem v3
We are here!
Net TS
Networking
HTTP etc.
TM TS
Transactional Memory
59. Wrap-Up
Tour around the new IDE New Library Features
Shell / Window handling std::async
Solution Explorer PPL
Code Navigation Improved container sizes
Better Intellisense
Snippets, Debug Experience
Parallel Watch, Threads, Tasks
New Compiler Features
New Language Features Code Analysis
auto, decltype, lambdas,
/SDL /GS
override, final
Auto Vectorization
static_assert, nullptr
Auto parallelization
C++ AMP
60. Philipp Aumayr
software architects gmbh
Q&A Mail philipp@timecockpit.com
Web http://www.timecockpit.com
Twitter @paumayr
Thank your for coming!
Saves the day.
Editor's Notes
Snap window back to original: Ctrl + Double click headerPromoting Preview Tab -> Ctrl + Alt + Home (Pos1)
Promoting Preview Tab -> Ctrl + Alt + Home (Pos1)Show Themes (Dark / Light)
Demo: Open VC2012 solution, add a few Assert::Fail to make testing more interesting. Show what test classes are
Demo: Open up Ogre SDK -> show that included Ogre.h works for intellisense