SG 9 (Ranges) mailing list is now open

Marshall Clow, chair of SG9 (Ranges) has announced the SG9 mailing list is now open:

Sign up at http://www.open-std.org/mailman/listinfo/ranges.

I'll post a welcome message to start off the discussion on Wednesday morning; please hold off on posting until then so that people have a chance to join.

Thanks - and have a Happy New Year!

-- Marshall

P.S. thanks to Keld [Simonsen] for setting up the list.

You Don't Know const and mutable -- Herb Sutter

In August, Herb Sutter gave a brand new 30-min talk at C++ and Beyond where he laid out the fundamentally new meanings of two long-time C++ keywords:

You Don't Know [const] and [mutable]

Herb Sutter

There’s a major change in C++11 that [...] rewrites pre-C++11 design guidance and is directly related to writing solid code in a concurrent and parallel world. And it isn’t just academic — everyone is going to have to learn and apply the new C++11 guidance that we’ll cover in this session.

This is a great example of how C++11 is a simpler language: We can stop the Cold War-era waffling about subtleties about what 20th-century C++ const means, and proudly declare modern C++ const has the simple and natural and "obvious" meaning that most people expected all along anyway.

One of the most common questions after the talk was, "Do other C++ experts agree with Herb's conclusions?" The answer is yes -- regarding his upcoming The C++ Programming Language, Fourth Edition, Bjarne Stroustrup writes: "I do point out that const means immutable and absence of race conditions in the last Tour chapter. I plan more for the concurrency chapter." Look for the third Tour chapter to be posted here next week, and the aforementioned last Tour chapter to be posted here in early February.

Enjoy.

Using constexpr to Improve Security, Performance and Encapsulation in C++ -- Danny Kalev

How is constexpr different from const, and how does it contribute to making modern C++ code cleaner and simpler, as well as faster than ever? Danny Kalev gives a nice summary:

Using constexpr to Improve Security, Performance and Encapsulation in C++

by Danny Kalev

constexpr is a new C++11 keyword that rids you of the need to create macros and hardcoded literals. It also guarantees, under certain conditions, that objects undergo static initialization. Danny Kalev shows how to embed constexpr in C++ applications to define constant expressions that might not be so constant otherwise.

Continue reading...

Quick Q: A unique_ptr is not copyable, so why can I return one by value? -- StackOverflow

 

A common question for programmers new to C++11 and its new features: "Hey, look how easy this was! ... But, um, why and how did it work?"

Returning unique_ptr from functions

unique_ptr<T> does not allow copy construction, instead it supports move semantics. Yet, I can return a unique_ptr<T> from a function and assign the returned value to a variable.

#include <iostream>
#include <memory>
using namespace std;

unique_ptr<int> foo()
{
  unique_ptr<int> p( new int(10) );
  return p;                   // 1
  //return move( p );         // 2
}

int main()
{
  unique_ptr<int> p = foo();
  cout << *p << endl;
  return 0;
}

The code above compiles and works as intended. So how is it that line 1 doesn't invoke the copy constructor and result in compiler errors? If I had to use line 2 instead it'd make sense (using line 2 works as well, but we're not required to do so).

I know C++0x allows this exception to unique_ptr since the return value is a temporary object that will be destroyed as soon as the function exits, thus guaranteeing the uniqueness of the returned pointer. I'm curious about how this is implemented, is it special cased in the compiler or is there some other clause in the language specification that this exploits?

Continue reading...

Qt 5 C++ UI framework released

Qt 5 is now available. This is the first major release under Digia, who recently acquired Qt from Nokia. Key additions include support for C++11 and HTML5 along with an integrated WebKit2 browser engine. Both commercial and open source versions are available.

Qt is the most widely-known and -used portable UI framework for C++, used by nearly half a millon developers worldwide. It offers native code performance and modern sophisticated user experiences across desktop, embedded, and mobile platforms.

More details from the Qt 5 product page:

Our 5th big iteration deepens four essential aspects of the Qt offering:

Amazing graphic capabilities and performance, especially manifested in constrained environments like embedded and mobile devices. Qt Quick 2 offers a GL-based scene graph, a particle system and a collection of shader effects. Qt Multimedia and Qt Graphical Effects bring these features even further.

Developer productivity and flexibility, making JavaScript and QML first class citizens while keeping the C++ foundation and Qt Widget support. The addition of Qt WebKit 2 should make HTML5 developers feel at home.

Cross-platform portability is now simpler for OS developers thanks to the new structure of Essentials and Add-ons modules, plus the consolidation of Qt Platform Abstraction. We look forward to seeing Qt running in all kinds of environments! Next up is full Qt support on iOS and Android and work here has already begun.

Open development and open governance is assuring wider development and testing of Qt 5 by a growing community including developers from Digia, KDAB, Intel, Collabora, Accenture, the KDE project, and many more companies and individuals. Today we all celebrate!

What’s new:

 

  • Amazing Graphics Capability and Performance
  • Qt Quick in Qt 5
  • WebKit and HTML5
  • Multimedia
  • Modularized Qt Libraries
  • Widgets in Qt 5
  • Qt Platform Abstraction
  • New Connection Syntax
  • Connectivity and Networking
  • JSON Support
  • User Input

 

Continue reading:

C++11: A cheat sheet -- Alex Sinyakov

Want a quick "cheat sheet" overview of what's new in C++11? Alex Sinyakov recently gave a presentation on this topic and has posted slides that are useful as a capsule summary in flash card form:

C++11 (PDF slides)

Alex Sinyakov, AMC Bridge LLC

Slide after slide shows C++11 code side by side with the same code written in older C++ style or in other languages. You'll quickly notice a pattern: In example after example, C++11 code is clean, safe, and as fast as ever... and sometimes even faster.

As Bjarne Stroustrup puts it: "Surprisingly, C++11 feels like a new language: The pieces just fit together better than they used to and I find a higher-level style of programming more natural than before and as efficient as ever."

Enjoy these great quick study notes as a refresher before your next C++11 interview.

For a detailed treatment of what’s new in C++11, see Overview of the New C++ (C++11) by Scott Meyers, featured on our Get Started! page. These are Scott’s fully-annotated color training materials from his course of the same name, and the best current approximation of “a book on what’s new in C++11.” (Free sample available.)

Best of 2012: auto

Perhaps the most common single question about C++11 is: When should we use auto to declare local variables?

Here's a current set of responses on Programmers.StackExchange. Enjoy.

Does auto make C++ code harder to understand?

I saw a conference by Herb Sutter where he encourages every C++ programmer to use auto.

I had to read C# code some time ago where var was extensively used and the code was very hard to understand -- every time var was used I had to check the return type of the right side. Sometimes more than once, because I forgot the type of the variable after a while!

I know the compiler knows the type and I don’t have to write it, but it is widely accepted that we should write code for programmers, not for compilers.

I also know that is more easy to write:

auto x = GetX();

Than:

 

someWeirdTemplate<someOtherVeryLongNameType, ...>::someOtherLongType x = GetX();

But this is written only once and the GetX() return type is checked many times to understand what type x has.

This made me wonder -- does auto make C++ code harder to understand?

Continue reading...

Quick Q: Inserting a variadic argument list into a vector? -- StackOverflow

From StackOverflow [c++11]:

I have an object that needs to take a variadic argument list in its constructor and store the arguments in a vector. How do I initialize a vector from a the arguments of a variadic constructor?

class GenericNode {
public:
    GenericNode(GenericNode*... inputs) {
            /* Something like... */
        // inputs_.push_back(inputs)...;
}
private:
    std::vector<GenericNode*> inputs_;
};

Continue reading...