April 2014

Programming Conversations Lecture Series -- Alexander Stepanov

alex-stepanov-programming-conversations.PNGYet again the wonderful ongoing video series from Alexander Stepanov and Paramjit Oberoi (A9 Organization):

Programming Conversations

Programming conversations is intended as an interactive course on programming. We'll try to practice the Socratic method: eventually there will be very little lecturing, and most of the time will be spent in discussions and in writing code together. We plan to cover a wide variety of topics, starting with the nature of programming, and continuing, in no particular order, with benchmarking, algorithms, data structures, caches, instruction level parallelism, generic programming, variable sized types, and Platonic ideas.

Most of the concepts are explained in terms of C++11/STL/Boost.

Source code is available.

 

 

 

 

GCC 4.9.0 released, full of improved C++11 and C++14 features

GCC 4.9.0 is now available, with further improved C++11 and C++14 conformance.

GCC 4.9.0 Released

by Jakub Jelinek

From the announcement:

Support for various C++14 additions have been added to the C++ Front End, on the standard C++ library side the most important addition is support for the C++11 <regex>. ...

Various kinds of undefined behaviors in programs can be now diagnosed at runtime through Undefined Behavior Sanitizer. ...

See http://gcc.gnu.org/gcc-4.9/changes.html for more information about changes in GCC 4.9.

From the Changes page:

The G++ implementation of C++1y return type deduction for normal functions has been updated to conform to N3638, the proposal accepted into the working paper. Most notably, it adds decltype(auto) for getting decltype semantics rather than the template argument deduction semantics of plain auto:

int& f();
         auto  i1 = f(); // int
decltype(auto) i2 = f(); // int&
G++ supports C++1y lambda capture initializers:
[x = 42]{ ... };
Actually, they have been accepted since GCC 4.5, but now the compiler doesn't warn about them with -std=c++1y, and supports parenthesized and brace-enclosed initializers as well.
G++ supports C++1y variable length arrays. G++ has supported GNU/C99-style VLAs for a long time, but now additionally supports initializers and lambda capture by reference. In C++1y mode G++ will complain about VLA uses that are not permitted by the draft standard, such as forming a pointer to VLA type or applying sizeof to a VLA variable. Note that it now appears that VLAs will not be part of C++14, but will be part of a separate document and then perhaps C++17.
void f(int n) {
  int a[n] = { 1, 2, 3 }; // throws std::bad_array_length if n < 3
  [&a]{ for (int i : a) { cout << i << endl; } }();
  &a; // error, taking address of VLA
}
G++ supports the C++1y [[deprecated]] attribute modulo bugs in the underlying [[gnu::deprecated]] attribute. Classes and functions can be marked deprecated and a diagnostic message added:
class A;
int bar(int n);
#if __cplusplus > 201103
class [[deprecated("A is deprecated in C++14; Use B instead")]] A;
[[deprecated("bar is unsafe; use foo() instead")]]
int bar(int n);

int foo(int n);
class B;
#endif
A aa; // warning: 'A' is deprecated : A is deprecated in C++14; Use B instead
int j = bar(2); // warning: 'int bar(int)' is deprecated : bar is unsafe; use foo() instead

G++ supports C++1y digit separators. Long numeric literals can be subdivided with a single quote ' to enhance readability:

int i = 1048576;
int j = 1'048'576;
int k =0x10'0000;
int m = 0'004'000'000;
int n = 0b0001'0000'0000'0000'0000'0000;
double x = 1.602'176'565e-19;
double y = 1.602'176'565e-1'9;
G++ supports C++1y polymorphic lambdas.
// a functional object that will increment any type
auto incr = [](auto x) { return x++; };

Runtime Library (libstdc++)

Improved support for C++11, including:

  • support for <regex>;
  • The associative containers in <map> and <set> and the unordered associative containers in <unordered_map> and <unordered_set> meet the allocator-aware container requirements;

Improved experimental support for the upcoming ISO C++ standard, C++14, including:

  • fixing constexpr member functions without const;
  • implementation of the std::exchange() utility function;
  • addressing tuples by type;
  • implemention of std::make_unique;
  • implemention of std::shared_lock;
  • making std::result_of SFINAE-friendly;
  • adding operator() to integral_constant;
  • adding user-defined literals for standard library types std::basic_string, std::chrono::duration, and std::complex;
  • adding two range overloads to non-modifying sequence oprations std::equal and std::mismatch;
  • adding IO manipulators for quoted strings;
  • adding constexpr members to <utility>, <complex>, <chrono>, and some containers;
  • adding compile-time std::integer_sequence;
  • adding cleaner transformation traits;
  • making <functional>s operator functors easier to use and more generic;

An implementation of std::experimental::optional.

An implementation of std::experimental::string_view.

The non-standard function std::copy_exception has been deprecated and will be removed in a future version. std::make_exception_ptr should be used instead.

CS 251: Intermediate Software Design in C++ -- Doug Schmidt

Doug Schmidt's C++-based software design course is available on YouTube.:

CS 251: Intermediate Software Design in C++

by Douglas Schmidt

This video playlist contains screencasts from a course I'm teaching on advanced C++ and object-oriented patterns/frameworks in the Spring of 2014 at Vanderbilt University. Please see http://www.dre.vanderbilt.edu/~schmidt/cs251/ for more information on this course.

Topics covered include:

  • Overview of C++ (3 lectures)
  • Overview of Subversion
  • Overview of the STL (8 lectures)
  • Overview of Patterns (2 lectures)
  • A Case Study of "Gang-of-Four" Patterns (8 lectures)

About the instructor:

Douglas C. Schmidt is a Professor of Computer Science, Associate Chair of the Computer Science and Engineering program, and a Senior Researcher at the Institute for Software Integrated Systems, all at Vanderbilt University. He has also been the Chief Technology Officer for the Software Engineering Institute at Carnegie Mellon University, where he was responsible for directing the technical vision and strategic R&D investments.

C++ developers will know of Doug particularly because of his widely-acclaimed ACE and related libraries.

Understanding the New Set and Map Containers in the C++11 Standard Library -- S Clamage and D Gove

On the Oracle Tech Network, a nice reminder of the still-"new"-to-some hash-based containers, co-authored by the chair of the U.S. C++ standards committee:

Understanding the New Set and Map Containers in the C++11 Standard Library

by Steve Clamage and Darryl Gove

From the article:

One of the areas in the new C++ standard that has seen the most enhancement is the Standard Library. The functionality that is most likely to be immediately useful to developers is the additions to the container classes. This article describes the new set and map containers.

Parallel STL: Democratizing Parallelism in C++ -- Artur Laksberg

Today on VCblog:

Parallel STL: Democratizing Parallelism in C++

by Artur Laksberg

From the article:

Over the last few years, a group of software engineers from Intel, Microsoft and NVidia have worked together on a proposal for the ISO C++ Standard known as the "Parallel STL".

This proposal builds on the experience of these three companies building parallel libraries for their platforms -- the Threading Building Blocks (Intel), PPL and C++ AMP (Microsoft) and Thrust (NVidia). All these libraries have a common trait -- they allow developers to perform common parallel operations on generic containers. Naturally, this aligns very well with the goals of the C++ Standard Template Library.

All three companies are working on their implementations of the proposal. Today, we're pleased to announce that Microsoft has made the prototype of the proposal available as an open source project at ParallelSTL.codeplex.com.

We encourage everyone to head over to our CodePlex site and check it out. The proposal has been approved to be the foundation for the "Parallelism Technical Specification" by the ISO C++ Standards Committee ...

Quick Q: Why does this function take a parameter by value? -- StackOverflow

A classic on SO:

Why do we copy then move?

I saw code somewhere in which someone decided to copy an object and subsequently move it to a data member of a class. This left me in confusion in that I thought the whole point of moving was to avoid copying. Here is the example:

struct S
{
    S(std::string str) : data(std::move(str))
    {}
};

Here are my questions:

  • Why aren't we taking an rvalue-reference to str?
  • Won't a copy be expensive, especially given something like std::string?
  • What would be the reason for the author to decide to make a copy then a move?
  • When should I do this myself?

The standard way of converting between numbers and strings in C++11 -- Marius Bancila

Quick: Would you resort to stringstream? But that's so C++98... and so hard.

More people need to know about to_string and its cousins. Marius Bancila takes us for a short tour:

The standard way of converting between numbers and strings in C++11

by Marius Bancila

From the article:

C++11 provides several standard functions for converting numbers to strings and strings to numbers, all of them available in the <string> header.

For converting numbers to strings there are two new overloaded functions: to_string() and to_wstring(). They take one argument of various numeric types (int, long, long long, double, long double, etc.) and return either a std::string or a std::wstring with the number converted to text. ...

For the other way around of converting strings to numbers there are several overloaded methods (taking either a std::string or a std::wstring): ...

Ponder the use of unique_ptr to enforce the Rule of Zero -- Marco Arena

Marco Arena points out an important difference between shared_ptr and unique_ptr regarding polymorphic deletion. The article also shows two ways to equip unique_ptr with a type-erased deleter, one with no usage of dynamic dispatching.

Ponder the use of unique_ptr to enforce the Rule of Zero

by Marco Arena

I read the article "Enforcing the Rule of Zero" from latest Overload (of ACCU) and I'd like to point out something that I misapprehended at a first reading. ... a clever point the author underlines is about polymorphic deletion: what to do when we want to support polymorphic deletion, or when our classes have virtual functions? ...

Then the author suggests to use a shared_ptr: ...

CppCon 2014 super early bird almost sold out -- ~20 tickets left

cppcon-144.PNGIf you've been thinking of registering for CppCon, you can save by doing it in the next couple of days. Over at CppCon.org, Boris Kolpackov reports:

Super Early Bird Last Chance

In the past couple of weeks a lot of C++ enthusiasts have registered for CppCon 2014 and as a result we only have about 20 super early bird entries left. If you are planning to attend, this is your last chance to register at the most affordable price.

After the limited Super Early Bird is full, Early Bird registration will be available until the end of June. Student registrations are also available at a heavily subsidized rate to ensure students can take advantage of the program.

See also the Call For Submissions to see the kinds of topics that you can expect to see covered.