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

Boost 1.55.0 released!

Release 1.55.0 of the Boost C++ Libraries is now available:

Boost Version 1.55.0

These open-source libraries work well with the C++ Standard Library, and are usable across a broad spectrum of applications. The Boost license encourages both commercial and non-commercial use.

This release contains one new library and numerous enhancements and bug fixes for existing libraries.

New libraries:

  • Predef: This library defines a set of compiler, architecture, operating system, library, and other version numbers from the information it can gather of C, C++, Objective C, and Objective C++ predefined macros or those defined in generally available headers, from Rene Rivera.

Quick Q: Should you overload func(X) and func(X&&)? -- StackOverflow

Quick A: No. But you can and often should overload func(X&) with func(X&&) (with const on the parameter if appropriate in either or both).

Here is the salient part of the SO question -- ignore the question's original title, because it's perfectly fine to overload pass-by-reference and pass-by-rvalue-reference where the former can be implemented using the normal copy-and-swap idiom:

Move assignment incompatible with standard copy and swap

[...] Here the assignment to a should use the "Move Assignment" operator. But there is a clash with the "Standard Assignment" operator (which is written as your standard copy and swap).

> g++ --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/c++/4.2.1
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix

> g++ -std=c++11 String.cpp
String.cpp:64:9: error: use of overloaded operator '=' is ambiguous (with operand types 'String' and 'String')
    a   = String("Test Move Assignment");
    ~   ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
String.cpp:32:17: note: candidate function
        String& operator=(String rhs)
                ^
String.cpp:54:17: note: candidate function
        String& operator=(String&& rhs)
                ^

 

Input Iterators vs. Input Ranges -- Eric Niebler

Trust Eric Niebler to deliver the goods -- when it comes to insightful discussion, cool code, and shameless puns:

Input Iterators vs. Input Ranges

by Eric Niebler

From the article:

The solution to istream_iterator's woes will be to replace it with istream_range. Put simply, if we’re reading strings from a stream, the string needs to live somewhere. The iterator seemed like the logical place when we were all thinking strictly in terms of iterators. But with ranges, we now have a much better place to put it: in the range object.

Learn How To Program... with C++ -- Kate Gregory

kate-gregory-v2.jpgDo you know a beginner who'd like to learn C++? Or even just learn how to program... using C++?

Recently, C++ author and trainer Kate Gregory made a new 7-hour course available via Pluralsight. And not just any introductory course, but teaching C++ the way it should be taught... not "C and pointers first."

It's highly-rated, as with all of Kate's courses. Know about it and recommend it to newcomers.

Learn How to Program with C++

Instructor: Kate Gregory

If you've never programmed before, and you think you'd like to learn C++, why not learn it first? This course covers what you need to start writing real applications in C++.