Whats New in Visual Studio 2012 for C++ Developers


Published on

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

Published in: Technology
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • 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
  • [HKEY_CURRENT_USER\\Software\\Microsoft\\VisualStudio\\11.0_Config\\Debugger]"EnableNatvisDiagnostics"=dword:00000001
  • [HKEY_CURRENT_USER\\Software\\Microsoft\\VisualStudio\\11.0_Config\\Debugger]"EnableNatvisDiagnostics"=dword:00000001http://msdn.microsoft.com/en-us/library/vstudio/jj620914.aspx
  • VC2012:TestAuto, TestAuto2, show types in intellisense
  • Demo: TestDeclType, show types of variables using hover
  • Demo:TestRangeBasedForLoop, TestRangeBasedForLoopArray, TestRangeBasedForLoopCustomRange
  • Demo: TestLambdaFunctionAdd, TestLambdaFunctionCaptureValue, TestLambdaFunctionCaptureReference, TestLambdaFunctionMultiCapture, TestLambdaFunctionPassToFunction
  • Demo: TestLambdaFunctionAdd, TestLambdaFunctionCaptureValue, TestLambdaFunctionCaptureReference, TestLambdaFunctionMultiCapture, TestLambdaFunctionPassToFunction
  • Demo: TestInitializerList
  • Demo: VC2012CTP.cpp
  • Demo: TestMoveConstructor
  • Demo: TestAsync, TestPromise, TestTaskPPL
  • Demo: TestTaskPPL
  • Demo: VC2012 -> main.cppQvec / Qparmessages http://msdn.microsoft.com/en-us/library/jj658585.aspx
  • Demo: VC2012 -> uncomment AMP
  • http://msdn.microsoft.com/en-us/library/a5b9aa09.aspxDemo: ArrayOfByOne, RedundantCodeCheck
  • Intvector.snippet, debugging support
  • Demo: break in TestAsync
  • Whats New in Visual Studio 2012 for C++ Developers

    1. 1. Philipp Aumayr software architects gmbh Web http://www.timecockpit.com Mail philipp@timecockpit.comVisual C++ 2012 Twitter @paumayrImprovements over 2008 Saves the day.
    2. 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. 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. 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
    5. 5. Motivation STL improvements shared_ptr, unique_ptr unordered_set, unordered_map SCARY iterators + container sizes Move Semantics std::async Code Analysis SDL
    6. 6. Motivation Auto-vectorization Auto-parallelization C++ AMP A lot to learn, but well worth the effort!
    7. 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. 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. 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
    10. 10. Better Intellisense Uses an SDF (SQL CE database) instead of the ncb Faster More robust Demo
    11. 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. 12. Type Visualizers (Natvis) Example natvis file Allows conditional strings, node expansions, item lists, tree items, synthetic items, etc.
    13. 13. BreakNew EditorBetter IntellisenseUnit TestingCode CoverageCode Analysis#include completionNavigate ToType visualizers
    14. 14. Break Questions?
    15. 15. C++ Styles (Question)C with a C++ compiler?C with classes / inheritance? RAII, Exceptions, Smart pointer? STL? TMP?
    16. 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. 17. decltype Represents the type of the expression decltype(2*3) -> int decltype(a) -> type of a Why? Let types flow! Demo
    18. 18. Range based for loop New type of for loop Iterates all members of a collection Demo
    19. 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. 20. Lambdas Finally make STL algorithms useable Reduces amount of (boilerplate-)code No more functor classes!
    21. 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. 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
    23. 23. override and final
    24. 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. 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. 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
    27. 27. enum classes C++03 enums
    28. 28. enum classes C++11 enum classes
    29. 29. Initializer lists (CTP)
    30. 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. 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. 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
    33. 33. Move Semantics Dramatically changes style!C++03 C++11
    34. 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
    35. 35. Break C++11 auto, decltype, range-based for loop lambdas, explicit overrides, static_assert nullptr, variadic templates, initializer_lists, enum classes, move-semantics
    36. 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. 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
    38. 38. std::async T1 T2 (Blocks)Demo
    39. 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. 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. 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. 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. 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. 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
    45. 45. Smaller container sizes  X86 release, sizes in bytesContainer VC9 SP1 / SCL = 0 VC10 (2010) VC11 (2012) (2008)vector<int> 16 16 12deque<int> 32 24 20forward_list<int> N/A 8 4queue<int> 32 24 20stack<int> 32 24 20unordered_map<int, int> 44 44 32string 28 28 24wstring 28 28 24 ~14% less!
    46. 46. Smaller container sizes  x64 release, sizes in bytesContainer VC9 SP1 / SCL = 0 VC10 (2010) VC11 (2012) (2008)vector<int> 32 32 24deque<int> 64 48 40forward_list<int> N/A 16 8queue<int> 64 48 40stack<int> 64 48 40unordered_map<int, int> 88 88 64string 40 40 32wstring 40 40 32 ~20% less!
    47. 47. Code Analysis Static analysis Provides warnings at compile time Additionally to /GS and /SDL Detailed information on warning
    48. 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
    49. 49. Break std::async ppl auto vectorization auto parallelization container sizes code analysis
    50. 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. 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. 52. Parallel Stacks Window New view for debugging Better understanding of multi thread applications
    53. 53. Parallel Tasks Window Lists the task queues
    54. 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. 55. ShortcutsShortcut Action ShortcutStrg + , Navigate To Strg + Q Search MenuF12 Go To Definition Strg + K, C Comment linesUmschalt + F12 Find all references Strg + K, U Uncomment linesStrg + - Navigate Backwards Strg + M, O Collapse To definitionStrg + Umschalt + - Navigate Forwards Strg +M, X Expand All OutliningStrg + F Find in current file Strg +M, S Collapse Current RegionStrg + H Replace in current file Strg + M, E Expand Current Region
    56. 56. Break Custom snippets Debug view experience Parallel Stacks Parallel Tasks Parallel Watch Window code analysis Shortcuts
    57. 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. 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. 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. 60. Philipp Aumayr software architects gmbhQ&A Mail philipp@timecockpit.com Web http://www.timecockpit.com Twitter @paumayrThank your for coming! Saves the day.