intermediate

What is std::promise? -- StackOverflow

Inquiring minds want to know this classic question:

What is std::promise?

I'm fairly familiar with the new standard library's std::thread, std::async and std::future components (e.g. see this answer), which are straight-forward.

However, I cannot quite grasp what std::promise is, what it does and in which situations it is best used. The standard document itself doesn't contain a whole lot of information beyond its class synopsis, and neither does just::thread.

Could someone please give a brief, succinct example of a situation where an std::promise is needed and where it is the most idiomatic solution?

Quick Q: Why is noexcept not enforced at compile time? -- StackOverflow

NoSenseEtAl asked:

Why noexcept is not enforced at compile time?

As you might know C++11 has noexcept keyword. Now ugly part about it is this:

Note that a noexcept specification on a function is not a compile-time check; it is merely a method for a programmer to inform the compiler whether or not a function should throw exceptions.

http://en.cppreference.com/w/cpp/language/noexcept_spec

So is this a design failure on the committee part or they just left it as an exercise for the compile writers smile in a sense that decent compilers will enforce it, bad ones can still be compliant?

Optimizing C++ Code: Constant-Folding -- Jim Hogg

vc-team-blog.PNGThe Visual C++ Team Blog has been publishing an article series about optimizations that C++ compilers perform for you under the covers to make your code more efficient. This short nugget answers a question people sometimes ask: "What's constant folding, and why do I care?"

Optimizing C++ Code: Constant-Folding

by Jim Hogg

From the article:

This post examines Constant-Folding -- one of the simplest optimizations performed by the VC++ compiler.  In this optimization, the compiler works out the result of an expression while it is compiling (at “compile-time”), and inserts the answer directly into the generated code.  This avoids the cost of performing those same calculations when the program runs (at “runtime”).

Here is an example...

Modern C++ Programming with Test-Driven Development -- Jeff Langr

[Ed.: This upcoming book is currently in beta. Thanks Tom for pointing it out!]

 

langr-tdd.pngI have nothing to do with this book other than I've bought the beta book and am enjoying it thus far. It fills a gap in the market very nicely.

Modern C++ Programming with Test-Driven Development: Code Better, Sleep Better

by Jeff Langr, edited by Michael Swaine

If you program in C++ you’ve been neglected. Test-driven development (TDD) is a modern software development practice that can dramatically reduce the number of defects in systems, produce more maintainable code, and give you the confidence to change your software to meet changing needs. But C++ programmers have been ignored by those promoting TDD -- until now. In this book, Jeff Langr gives you hands-on lessons in the challenges and rewards of doing TDD in C++.

Auto: A Necessary Evil? -- Roger Orr

Roger Orr has written about the history and use of auto in ACCU's Overload 115:

Auto -- A Necessary Evil?

by Roger Orr

From the article:

The keyword auto now lets you declare variables where the compiler provides the actual type and the programmer is either unwilling or unable to name the actual type. The keyword can also be used in function definitions to let you provide the return type after the rest of the function declaration, which is useful when the return type depends on the type of the arguments.

As with any new keyword there are questions about usage –- at two levels. First of all, where and how are programmers permitted to use the new feature. Secondly, what guidance is there to sensible adoption of the new feature. I intend to start with by answering the first question and then subsequently focus on the second.

Quick Q: Are there significant differences between boost::bind and std::bind? -- StackOverflow

A few minutes ago on SO:

Should I be seeing significant differences between std::bind and boost::bind?

I'm exploring the support for C++11 on the 4.7 branch of g++ (Ubuntu/Linaro 4.7.3-2ubuntu~12.04, to be specific) and I seem to be finding differences. In particular, if I comment out the #include of boost/bind.hpp and systematically replace occurrences of boost::bind with std::bind in the Boost ASIO async client example (taken from http://www.boost.org/doc/libs/1_45_0/doc/html/boost_asio/example/http/client/async_client.cpp), the program no longer compiles. Any explanation for this?

 

Boost 1.54.0 released!

Release 1.54.0 of the Boost C++ Libraries is now available.

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 five new libraries and numerous enhancements and bug fixes for existing libraries.

New Libraries:
Log: Logging library, from Andrey Semashev.
TTI: Type Traits Introspection library, from Edward Diener.
Type Erasure: Runtime polymorphism based on concepts.

For details, including download links, see http://www.boost.org/users/news/version_1.54.0

You can also download directly from SourceForge: http://sourceforge.net/projects/boost/files/boost/1.54.0/

To install this release on your system, see http://www.boost.org/doc/libs/release/more/getting_started/index.html

Thanks,

--The Boost release team

Scott Meyers speaking at NWC++UG -- July 17, Redmond, WA, USA

In three weeks, Scott Meyers will be giving a free talk at the Northwest C++ Users' Group:

The Universal Reference/Overloading Collision Conundrum

by Scott Meyers

July 17, 2013 at 7:00pm (pizza at 6:45)
Microsoft Campus, Building 40
Redmond, WA, USA

Abstract

To help address the confusion that arises when rvalue references become lvalue references through reference collapsing, Scott Meyers introduced the notion of “universal references.” In this presentation, he builds on this foundation by explaining that overloading functions on rvalue references is sensible and useful, while seemingly similar overloading on universal references yields confusing, unhelpful behavior. But what do you do when you want to write a perfect forwarding function (which requires universal references), yet you want to customize its behavior for certain types? If overloading is off the table, what’s on? In this talk, Scott surveys a variety of options.

Though Scott will give a one-slide overview of the idea behind universal references at the beginning of the presentation, attendees are encouraged to familiarize themselves with the notion in more detail prior to the talk. Links to written and video introductions to universal references are available here.

Bio

Scott Meyers is one of the world’s foremost authorities on C++. He wrote the best-selling Effective C++ series (Effective C++, More Effective C++, and Effective STL); published and maintains the annotated training materials Overview of the New C++ (C++11) and Effective C++ in an Embedded Environment; is Consulting Editor for Addison Wesley’s Effective Software Development Series, and, with Herb Sutter and Andrei Alexandrescu, is a principal in C++ and Beyond. He has a Ph.D in Computer Science from Brown University. He’s currently working on a new book, Effective C++11/14, which he hopes to publish in early 2014.