March 2013

Quick Q: What's the difference between result_of and decltype? -- StackOverflow

From SO:

What's the difference between result_of<F(Args…> and decltype<f(args…)>?

I see that std::async is specified as follows:

template <class F, class... Args>                   // copied out of the standard
future<typename result_of<F(Args...)>::type>
async(F&& f, Args&&... args);

I had expected it to be declared like this:

template <class F, class... Args>
auto async(F&& f, Args&&... args) ->
  future<decltype(f(forward<Args>(args)...)>;

Would that be equivalent, or is there some way in which the use of result_of is preferable to the use of decltype? (I understand that result_of works with types, while decltype works with expressions.)

Preface for The C++ Programming Language 4th Ed. now available

The Preface for The C++ Programming Language, 4th Ed., is now available on InformIT and also appears in full on this site's Tour of C++ page.

Preface to TC++PL4e

All problems in computer science can be solved by another level of indirection, except for the problem of too many layers of indirection.

            -- David J. Wheeler

C++ feels like a new language. That is, I can express my ideas more clearly, more simply, and more directly in C++11 than I could in C++98. Furthermore, the resulting programs are better checked by the compiler and run faster. ...

The use of C++ has changed dramatically over the years and so has the language itself. From the point of view of a programmer, most of the changes have been improvements. The current ISO standard C++ (ISO/IEC 14882:2011, usually called C++11) is simply a far better tool for writing quality software than were previous versions. How is it a better tool? What kinds of programming styles and techniques does modern C++ support? What language and standard-library features support those techniques? What are the basic building blocks of elegant, correct, maintainable, and efficient C++ code? Those are the key questions answered by this book. Many answers are not the same as you would find with 1985, 1995, or 2005 vintage C++: progress happens.

Continue reading...

 

A Look at C++14: Papers Part I -- Meeting C++

[Ed. Note: Although labeled "A look at C++14," not all of these papers are for C++14, and regardless of timeframe not all will be adopted. But it is a useful look at what's on the commitee's radar.]

As we gear up for the Bristol meeting that starts on April 15, the committee members now are busily reading and preparing positions on the many papers to be considered at the meeting.

Since our last meeting in Portland, we have a recent-record-level 160 technical papers, most of which are proposals that will need to be considered and discussed at the face-to-face meeting.

Those papers have been posted here; see the blog's Standardization category. Most recently, the papers have been posted individually with crafted excerpts, and many committee members have found that useful and already follow the mailings primarily here on the blog like everyone else.

However, it's not just the committee members who are interested in these proposals. The Meeting C++ blog has posted the first of a multi-part series of "digest" summaries of the papers in the March mailing (they skipped the January mailing). In this first installment, they summarize a first batch of papers...

A look at C++14: Papers Part I

This is the first Part of n, or lets say many entries in this blog. In total I hope to be able to cover most papers in 3-4 blog posts, giving the reader an overview over the suggestions and changes for C++ at the coming C++ Committee Meeting in April. In total there are 98 Papers, so I will skip some, but try to get as much covered as possible. I'll skip papers with Meeting Minutes for sure, and try to focus on those focusing on C++11 or C++14 features. As the papers are ordered by there Number (N3522 being the first), I'll go top down, so every blog post will contain different papers from different fields of C++ Standardization. As N352-24 are Reports about Active Issues, Defects and Closed Issues I'll skip them for now, also I will not read through Meeting Minutes and such.

Quick Q: So what's "lite" about "concepts lite" vs. full concepts?

There's a Q&A on StackOverflow, but see also the discussion about this in the March 12 Concepts conference call minutes that were posted here on the same day as the call. It's really more than minutes, it's also a record of discussion that answers this and other questions.

From SO:

What are the differences between concepts and template constraints?

I want to know what are the semantic differences between the C++ full concepts proposal and template constraints (for instance, constraints as appeared in Dlang or the new concepts-lite proposal for C++1y).

What are full-fledged concepts capable of doing than template constraints cannot do?

Quick Q: How should you use the standard smart pointers as members? -- StackOverflow

From StackOverflow:

Using smart pointers for class members

I'm having trouble understanding the usage of smart pointers as class members in C++11. I have read a lot about smart pointers and I think I do understand how unique_ptr and shared_ptr/weak_ptr work in general. What I don't understand is the real usage. It seems like everybody recommends using unique_ptr as the way to go almost all the time. But how would I implement something like this: ...

Quick Q: Why does emplace_back need a (copy or) move constructor? -- StackOverflow

Quick A: It needs it when the container is a vector or similar, because the container may need to grow and reallocate which includes moving or copying the existing contents to the new location.

why does emplace_back need move constructor?

I have the following code... But the emplace_back doesn't use the move constructor. Why does the initialization require a move constructor in this instance?

Qt Creator 2.7.0: More C++11, and C++11 Now Default

Qt Creator 2.7.0 is now available, and includes more C++11 support including that C++11 mode is now on by default.

Qt Creator 2.7.0 Released

by Eike Ziller

C++ support in Qt Creator got even more improvements for C++11, like handling of alignof, alignas and noexcept, brace initializers, and more lambda fixes. Also, if Qt Creator cannot find out if your tool chain expects C++11 or C++98/03, it defaults to C++11 now, for a better out of the box experience.