November 2013

Visual C++ November 2013 CTP released, adds 13 new C++11/14 features

vc-ctp-nov13.PNGMicrosoft has announced a new Visual C++ Compiler CTP (Community Technology Preview):

Announcing the Visual C++ Compiler November 2013 CTP

In addition to the ISO C++ features added in last month's Visual c++ 2013 full release, this CTP adds the following additional ISO C++11 and draft ISO C++14 features in preview form:

  • Implicit move special member function generation (thus also completing =default)
  • Reference qualifiers on member functions (a.k.a. "& and && for *this")
  • Thread-safe function local static initialization (a.k.a. "magic statics")
  • Inheriting constructors
  • alignof/alignas
  • __func__
  • Extended sizeof
  • constexpr (except for member functions)
  • noexcept (unconditional)
  • C++14 decltype(auto)
  • C++14 auto function return type deduction
  • C++14 generic lambdas (with explicit lambda capture list)
  • (Proposed for C++17) Resumable functions and await

The new CTP installs as a new toolset under the Visual C++ 2013 IDE, allowing editing and building using the new Visual C++ compiler through the current shipping IDE. As this is a CTP, however, there is not yet other IDE support, and so for example the IDE may display red squiggles on valid code that will actually compile and run, as shown in the accompanying screenshot which exercises a generic lambda function having an auto parameter. If you do not already have a copy of Visual C++ 2013 installed and would like a free copy, several versions of the Visual C++ 2013 Express optimizing compiler are available for free via the Visual Studio Downloads page. 

New Stable Major wxWidgets 3.0.0 Release

logo9.jpgA new stable release of wxWidgets, the open source C++ library for creating cross-platform GUI applications with native look and feel, is now available.

This 3.0 release is a culmination of several years of work since the previous stable 2.8 series and so brings many important improvements compared to it, such as:

  • Much better and simpler to use support for Unicode.
  • New wxOSX/Cocoa port, suitable for development of 64 bit GUI applications under OS X.
  • Support for GTK+ 3 in wxGTK port.
  • Much improved documentation.
  • New webview library providing integration with the platform native HTML-rendering engine.
  • New propgrid and ribbon libraries.
  • New wxRichMessageDialog, wxInfoBar, wxCommandLinkButton, wxHeaderCtrl, wxRearrangeCtrl, wxTreeListCtrl, wxTimePickerCtrl, wxRichToolTip, wxBannerWindow, wxPersistentXXX and other classes.

as well as a huge number of other new features and bug fixes.

More information is available at wxWidgets home page and in the online documentation.

Quick Q: Can you move out of an initializer_list? -- StackOverflow

Quick A: No, because the contents are const.

A classic from SO, recommended by a developer team that encountered this situation again in the past week:

initializer_list and move semantics

Am I allowed to move elements out of a std::initializer_list<T>?

#include <initializer_list>
#include <utility>

template<typename T>

void foo(std::initializer_list<T> list)
{
    for (auto it = list.begin(); it != list.end(); ++it)
    {
        bar(std::move(*it));   // kosher?
    }
}

Since std::intializer_list<T> requires special compiler attention and does not have value semantics like normal containers of the C++ standard library, I'd rather be safe than sorry and ask.

The best of Boost, and using Boost the best

boost-books-2.pngWell timed with the recent release of Boost 1.55, a new Reddit thread just highlighted two useful books about Boost:

The first book is available online, with a second edition released in print in 2011:

The Boost C++ Libraries

by Boris Schäling

Table of Contents

  • Chapter 1: Introduction
  • Chapter 2: Smart Pointers
  • Chapter 3: Function Objects
  • Chapter 4: Event Handling
  • Chapter 5: String Handling
  • Chapter 6: Multithreading
  • Chapter 7: Asynchronous Input and Output
  • Chapter 8: Interprocess Communication
  • Chapter 9: Filesystem
  • Chapter 10: Date and Time
  • Chapter 11: Serialization
  • Chapter 12: Parser
  • Chapter 13: Containers
  • Chapter 14: Data Structures
  • Chapter 15: Error Handling
  • Chapter 16: Cast Operators

The second, the subject of the Reddit thread, was this new release:

Boost C++ Application Development Cookbook

by Antony Polukhin

Overview

  • Explores how to write a program once and then use it on Linux, Windows, MacOS, and Android operating systems
  • Includes everyday use recipes for multithreading, networking, metaprogramming,  and generic programming from a Boost library developer
  • Take advantage of the real power of Boost and C++ to get a good grounding in using it in any project

Table of Contents

  • Preface
  • Chapter 1: Starting to Write Your Application
  • Chapter 2: Converting Data
  • Chapter 3: Managing Resources
  • Chapter 4: Compile-time Tricks
  • Chapter 5: Multithreading
  • Chapter 6: Manipulating Tasks
  • Chapter 7: Manipulating Strings
  • Chapter 8: Metaprogramming
  • Chapter 9: Containers
  • Chapter 10: Gathering Platform and Compiler Information
  • Chapter 11: Working with the System
  • Chapter 12: Scratching the Tip of the Iceberg

Meeting C++ 2013

The recent Meeting C++ 2013 was a blast, the 2nd Meeting C++ conference was with over 200 guests a full success!

Meeting C++ 2013

by Jens Weller

Additional Online Resources:

Stephen Kelly about CMake for Qt and Boost

The talks from Peter Sommerlad

Sven Johannsens HTML based talk about STL11 is online.

Available slides are linked in the talk descriptions.

HPX version 0.9.7 released -- STE||AR Group, LSU

The STE||AR Group at Loisiana State University has released V0.9.7 of HPX -- A general purpose parallel C++ runtime system for applications of any scale.

HPX V0.9.7 Released

The newest version of HPX (V0.9.7) is now available for download! Over the past few months...

From the announcement:

  • Ported HPX to BlueGene/Q
  • Improved HPX support for Intel Xeon Phi® accelerators.
  • Reimplemented hpx::bind, hpx::tuple, and hpx::function for better performance and better compliance with the C++11 Standard. Added hpx::mem_fn.
  • Reworked hpx::when_all and hpx::when_any for better C++ compliance. Added hpx::when_any_swapped.
  • Added hpx::copy as a precursor for a migrate functionality, added hpx::get_ptr allowing to directly access the memory underlying a given component.
  • Added the hpx::lcos::broadcast, hpx::lcos::reduce, and hpx::lcos::fold collective operations.
  • Added support for more flexible thread affinity control from the HPX command line, such as new modes (balanced, scattered, compact), improved default settings when running multiple localities on the same node.
  • Added experimental executors for simpler thread pooling and scheduling. This API may change in the future as it will stay aligned with the ongoing C++ standardization efforts.
  • Massively improved the performance of the HPX serialization code. Added partial support for zero copy serialization of array and bitwise-copyable types.
  • General performance improvements of the code related to threads and futures.

Quick Q: Does using std:: smart pointers mean not using raw pointers? -- StackOverflow

Quick A: No. Smart pointers are for ownership. Raw pointers are still fine for non-owning pointers to an object that outlives the pointer.

C++11 Smart Pointer Semantics

I've been working with pointers for a few years now, but I only very recently decided to transition over to C++11's smart pointers (namely unique, shared, and weak). I've done a fair bit of research on them and these are the conclusions that I've drawn:

  1. Unique pointers are great. They manage their own memory and are as lightweight as raw pointers. Prefer unique_ptr over raw pointers as much as possible.
  2. Shared pointers are complicated. They have significant overhead due to reference counting. Pass them by const reference or regret the error of your ways. They're not evil, but should be used sparingly.
  3. Shared pointers should own objects; use weak pointers when ownership is not required. Locking a weak_ptr has equivalent overhead to the shared_ptr copy constructor.
  4. Continue to ignore the existence of auto_ptr, which is now deprecated anyhow.

So with these tenets in mind, I set off to revise my code base to utilize our new shiny smart pointers, fully intending to clear to board of as many raw pointers as possible. I've become confused, however, as to how best take advantage of the C++11 smart pointers. ...

Free introductory C++ web course on Tuesday November 19 -- Kate Gregory, James McNellis

gregory-mcnellis.PNGComing next week on Microsoft Virtual Academy:

C++: A General Purpose Language and Library

by Kate Gregory and James McNellis

Live on November 19, 2013, 9:00am-5:00pm PST (other time zones), later on demand

Cost: Free

With these speakers, we expect a high quality talk. If you're new to C++, or know someone who is and would like to learn about the language, watch and recommend this talk. This event uses the Microsoft Visual Studio environment, but the content is applicable to new C++ developers using any compiler and platform.

From the announcement:

Attention developers: here’s a painless way to learn the basics of C++ from the ground up, whether you’re updating legacy code or writing brand new, efficient, and high-performance code for new platforms like phones and want to take advantage of C++.  You’ll learn the fundamentals of the C++ language, how to use the language and its Standard Library effectively, and how to use the Visual Studio environment for developing C++, including debugging, exploring code, and understanding error messages.  This is your starting point for building software in C++.

COURSE OUTLINE

  • Introduction to Programming Concepts
  • Getting Started
  • The C++ Object Model
  • Pointers and Indirection
  • RAII – Resource Acquisition is Initialization
  • The C++ Standard Library (STL)

INSTRUCTOR TEAM

Kate Gregory | Partner, Gregory Consulting Limited | @gregcons

Kate Gregory is a C++ expert who has been using C++ since before Microsoft had a C++ compiler, an early adopter of many software technologies and tools, and a well-connected member of the software development community. She has over three decades of scientific and engineering programming experience in a variety of programming languages. Since January 2002 she has been Microsoft Regional Director for Toronto and since January 2004 she has been awarded the Microsoft Most Valuable Professional designation for Visual C++. In June 2005 she won the Regional Director of the year award, and she was one of the C++ MVPs of the year for 2010.
Kate is the author of over a dozen books, mostly on C++ programming; the latest, on massively parallel programming with C++ AMP, was published in fall 2012 by Microsoft Press. Her firm, Gregory Consulting Limited, is based in rural Ontario and helps clients adopt new technologies and adjust to the changing business environment. Managing, mentoring, technical writing, and technical speaking occupy much of her time, but she still writes code every week.

James McNellis | Microsoft Senior Software Development Engineer | @JamesMcNellis

James McNellis is a computer programmer and C++ maven. A senior engineer on the Microsoft Visual C++ team, James builds modern C++ libraries and is the maintainer of the Visual C++, C Runtime (CRT), and C Standard Library implementation. He was previously a member of the Microsoft Expression Blend team, developing the XAML designer tools for Windows 8 apps. Prior to joining Microsoft in 2010, he spent several years working on real-time 3-D simulation and robotics projects in the defense industry. James is a prolific contributor on the Stack Overflow programming Q&A website and writes for the Visual C++ Team Blog.

Quick Q: May the return value optimization remove side effects of copying? -- StackOverflow

Quick A: Yes. That's kind of the point, actually.

This weekend on StackOverflow:

Return value optimizations and side-effects

Return value optimization (RVO) is an optimization technique involving copy elision, which eliminates the temporary object created to hold a function's return value in certain situations. I understand the benefit of RVO in general, but I have a couple of questions.

The standard says the following about it in §12.8, paragraph 32 of this working draft (emphasis mine).

When certain criteria are met, an implementation is allowed to omit the copy/move construction of a class object, even if the copy/move constructor and/or destructor for the object have side effects. In such cases, the implementation treats the source and target of the omitted copy/move operation as simply two different ways of referring to the same object, and the destruction of that object occurs at the later of the times when the two objects would have been destroyed without the optimization.

It then lists a number of criteria when the implementation may perform this optimization.

I have a couple of questions regarding this potential optimization:

  1. I am used to optimizations being constrained such that they cannot change observable behaviour. This restriction does not seem to apply to RVO. Do I ever need to worry about the side effects mentioned in the standard? Do corner cases exist where this might cause trouble?
  2. What do I as a programmer need to do (or not do) to allow this optimization to be performed? For example, does the following prohibit the use of copy elision (due to the move):
std::vector<double> foo(int bar){
    std::vector<double> quux(bar,0);
    return std::move(quux);
}