November 2013

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++.

Clang is (draft) C++14 feature-complete!

A few hours ago, Clang completed checkin 194194 to be feature-complete for draft C++14 including both language extensions and standard library features. (Note: The library conformance requires using libc++, instead of libstdc++ which is supported on more platforms but is not as conforming.) Congratulations to the Clang team for this achievement!

With this progress, it appears that the next release of Clang and LLVM, expected in December or January, will be draft C++14 feature-complete. C++14 itself may still undergo final changes at the February 2014 ISO C++ meeting, which is expected to be the final meeting for technical tweaks to the contents of C++14.

Why does C++ not allow multiple types in one auto statement? -- StackOverflow

Recently on SO:

Why does C++ not allow multiple types in one auto statement?

The 2011 C++ standard introduced the new keyword auto, which can be used for defining variables instead of a type, i.e.

auto p=make_pair(1,2.5);                   // pair<int,double>
auto i=std::begin(c), end=std::end(c);     // decltype(std::begin(c))

In the second line, i and end are of the same type, referred to as auto. The standard does not allow

auto i=std::begin(container), e=std::end(container), x=*i;

when x would be of different type. My question: why does the standard not allow this last line? ...

Ode To a Flat Set -- Jon Kalb

Grecian-Urn-187x300.jpegA nice short overview of when you might want your associative container to use a contiguous implementation instead of a tree under the covers:

Ode to a Flat Set

by Jon Kalb

From the article:

The Boost Container library has a family of flat_* containers that have associative container interfaces and semantics, but are implemented as sorted vectors.

In addition to faster lookup, the flat_* containers have much faster iteration, less memory overhead, fewer allocations, and improved cache performance.

However, as with all things, there are trade-offs.

Exception safety: The strong guarantee and move semantics

meyers-gn13.PNGAn interesting question was asked recently on StackOverflow that nicely ties in with Scott Meyers' "Effective C++11/14 Sampler" talk two months ago at GoingNative 2013 and the interestingly named feature std::move_if_noexcept, both referenced in the answers.

Since the gorier details of the answer lie in "watch Scott's talk," we merrily abuse a snapshot of Dr. Meyers during said talk as the highlight graphic for this post.

Exception safe code and move semantics

I want to write container class. This container has insert method that have two specializations -- first uses copy constructors to copy data from one container to another container element wise. If copy constructor throws exception I just undo all changes to the container like nothing happens.

The second specialization uses move constructor and thats the place where things got complicated. When I move items from one container to another container element by element, move constructor can throw exception. If this happens -- I've got really messy state when some elements are moved and other elements stays in it's original places. If I try to move elements back -- I can get another exception.

Is it possible to write something like this in exception safe manner or exception safety and move semantics are mutually exclusive?

Compiling and Linking in C++ -- Rusty Ocean

Selection_101.pngLife'n'gadget just published a nice overview of the basic C++ compilation model, useful for people who are new to programming in C++.

Compiling and Linking in C++

by Rusty Ocean

From the article:

When you write a C++ program, the next step is to compile the program before running it. The compilation is the process which convert the program written in human readable language like C, C++ etc into a machine code, directly understood by the Central Processing Unit. There are many stages involved in creating a executable file from the source file. The stages include Preprocessing, Compiling and Linking in C++...