News

Quick Q: What's the difference between std::merge and std::inplace_merge? -- StackOverflow

Quick A: "Inplace" can deal with overlapping ranges, but will take either more space or more time.

Today on StackOverflow:

Difference between std::merge and std::inplace_merge?

What is the difference between std::merge and std::inplace_merge in terms of complexity and result when it is executed on two consecutive ranges with elements that are all different ? (I am not a native english speaker and I am not sure to clearly understand what "inplace" means)

Overload 119 is now available

overload-119.PNGOverload 119 is now available. It contains the following C++-related articles, and more:

 

Overload 119

Feature: Static Polymorphic Named Parameters in C++ -- Martin Moene

Adding parameters to an object can be messy. Here is a description of method chaining -- an interesting way to pass parameters into methods in a more readable fashion.

Capturing Lvalue References in C++11 Lambdas -- Pete Barber

How confusing does it get when references refer to references and references are captured by value? Pete Barber shows us that it all falls out in the C++ consistency wash.

C++ Papers for Issaquah - Concepts, Database and Evolution

This is the second part of my series about the papers for the next C++ committee meeting in Issaquah:

C++ Papers for Issaquah - Concepts, Database & Evolution

by Jens Weller

From the article:

This is the second part about the papers for the C++ committee meeting in February in Issaquah. This time featuring papers from the subgroups of concept, database and evolution. Again, most papers in this series aim for a standard after C++14, most important for C++14 will be the national comments on the new standard. Also there are no new papers from the core working group, only the active issues, defects report and closed issues report are on this mailing.

 

Quick Q: Why does unique_ptr take two template parameters when shared_ptr only takes one? -- SO

Recently on StackOverflow:

Why does unique_ptr take two template parameters when shared_ptr only takes one?

Both unique_ptr and shared_ptr accept a custom destructor to call on the object they own. But in the case of unique_ptr, the destructor is passed as a template parameter of the class, wherease the type of shared_ptr's custom destructor is to be specified as a template parameter of the constructor.

template <class T, class D = default_delete<T>>
class unique_ptr
{
    unique_ptr(T*, D&); //simplified
    ...
};

and

template<class T>
class shared_ptr
{
    template<typename D>
    shared_ptr(T*, D); //simplified
    ...
};

I can’t see why such difference. What requires that?

Quick Q: What do braces mean as a function argument? -- StackOverflow

Quick A: Something cool and convenient -- you can construct a temporary variable of the parameter type without having to repeat the type.

From SO:

C++ 11 Curly Braces

I haven't used C++ for a good few years, and have just come across this:

program.build({ default_device })

The definition is:

cl_int build(
    const VECTOR_CLASS<Device>& devices,
    const char* options = NULL,
    void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
    void* data = NULL) const

What are the curly braces there for? I have never seen them used in a function call like this before. I assume it has something to do with the function pointer, but that seems optional?

N3906: ISO/IEC PDTS 18822, File System, National Body Comments -- Barry Hedquist

Note: These are the results of the main international review and comment ballot for the File System TS. The Issaquah ISO C++ meeting that begins on Monday will be a ballot resolution meeting for both C++14 and the File System TS.

A new WG21 paper is available. A copy is linked below, and the paper will also appear in the next normal WG21 mailing. If you are not a committee member, please use the comments section below or the std-proposals forum for public discussion.

Document number: N3906

Date: 2014-02-03

ISO/IEC PDTS 18822, File System, National Body Comments

by Barry Hedquist

Excerpt:

Attached is a revision of SC22 N4901, the complete set of National Body Comments submitted to JTC1 SC22 in response to the SC22 Letter Ballot for ISO/IEC PDTS 18822, File System.

C++ User Group Meetings in February

February will be a month full of C++ user group meetings:

C++ User Group Meetings in February

by Jens Weller

From the article:

There are a few new user groups, some of them even will meet in February for the first time. There is now a russian C++ users group organizing Meetings in St. Peterburg and Moscow. In Germany, the C++ user group Munich has met in January for the first time, with over 50 people attending the first meeting. In February the user groups of Aachen and Dortmund will meet for the first time. And, already meeting last year for the first time, there is now a dutch C++ user group!

C++ Papers for Issaquah -- Concurrency

So I just started to read through the papers for the next C++ committee meeting in Issaquah in February, first part is about Concurrency:

C++ Papers for Issaquah -- Concurrency

by Jens Weller

From the article:

In february the C++ committee is going to meet for a week in Issaquah, it could be the final Meeting for C++14, the papers in this series will reflect both, C++14 and the standard that will come after it. Currently mostly known as C++1y. A lot of papers that are not part of C++14 will be formed into technical specifications, which some will then become C++1y later. Like the last series, I will again focus on the working groups, and post the papers sorted by the name of the working group, starting with concurrency.

Stroustrup & Sutter on C++: Session information posted

eelive.PNGThe draft session titles and descriptions have now been posted for Bjarne Stroustrup's and Herb Sutter's two-day seminar on C++:

Super C++ Tutorial: Stroustrup & Sutter on C++

EE Live!
March 31 - April 1, 2014
McEnery Convention Center
San Jose, CA, USA

We invite you to spend two insightful and informative days with C++ luminaries Bjarne Stroustrup, the creator of C++, and Herb Sutter, the chair of the ISO C++ committee, as they address the most important issues for C++ developers in 2014.

The two days are designed to cover a balanced curriculum:

  • Useful pragmatic information for C++ developers, with helpful tips and techniques whether you’ve only used C++ for a few months or are a top C++ guru. Everyone should come away with something that elicits "I didn’t know that, I can use that tomorrow!" and "I have to think about that; it just might change my work dramatically."
  • Balanced coverage of both the core language with its powerful new features, and the expanding standard library.
  • Modern techniques and best practices you can use with current compilers, together with forward-looking information about new features coming and expected to be broadly available in the next year.
  • Panels where both speakers share their insights and perspectives and answer your questions.
  • And much more, with the deep context and expertise that only these instructors can uniquely bring.

As Standard C++ continues to evolve and accelerate, this is a rare opportunity to spend time with these two world leaders of all things C++.

Below is a partial list of topics the speakers will cover.

The Essence of C++ (Bjarne Stroustrup)

C++11 is being deployed and the shape of C++14 is becoming clear. This talk examines the foundations of C++. What is essential? What sets C++ apart from other languages? How do new and old features support (or distract from) design and programming relying on this essence?

This talk focuses on the abstraction mechanisms (as opposed to the mapping to the machine): Classes and templates. Fundamentally, if you understand vector, you understand C++.

Type safety and resource safety are key design aims for a program. These aims must be met without limiting the range of applications and without imposing significant run-time or space overheads. This talk addresses issues of resource management (garbage collection is not an ideal answer and pointers should not be used as resource handles), generic programming (we must make it simpler and safer), compile-time computation (how and when?), and type safety (casts belongs in the lowest-level hardware interface). It will touch upon move semantics, exceptions, concepts, type aliases, and more. The aim is not so much to present novel features and technique, but to explore how C++’s feature set supports a new and more effective design and programming style.

C++11/14 Style (Herb Sutter)

This session will cover modern and current C++ style, focusing on C++14. It will demonstrate how major features and idioms from C++98 are now entirely replaced or subsumed and should be used no more; how other major features and idioms have been dramatically improved to the point where you code is cleaner and safer and you’ll even think in a different style; and how pervasive styles as common as variable declarations are changed forever, and not just for style but for serious technical safety and efficiency benefits. For one thing, you’ll never look at auto the same way again -- and if hearing that makes you worry, worry not, just attend the session to dig deep into the good reasons for the new reality.

Why C++14? Two reasons: First, it really does "complete C++11" with small but important consistency features like generic lambdas and make_unique that let us teach modern C++ style with fewer "except for" footnotes. Second, C++14 "is" C++ for the next several years and it’s real; it is feature-complete and in the final stages of standardization, and more importantly we are already seeing near-complete conforming implementations becoming widely available around the same time C++14 is expected to be formally published.

C++14 is a small but important improvement on C++11 that really does complete the language. What this means is that we’re going to have a complete and simpler set of idioms and styles to learn and use.

Generic Programming and Concepts (Bjarne Stroustrup)

C++ does not provide facilities for directly expressing what a function template requires of its set of parameters. This is a problem that manifests itself as poor error messages, obscure bugs, lack of proper overloading, poor specification of interfaces, and maintenance problems.

Many have tried to remedy this (in many languages) by adding sets of requirements, commonly known as "concepts." Many of these efforts, notably the C++0x concept design, have run into trouble by focusing on the design of language features.

This talk presents the results of an effort to first focus on the design of concepts and their use; Only secondarily, we look at the design of language features to support the resulting concepts. We describe the problem, our approach to a solution, give examples of concepts for the STL algorithms and containers, and finally show an initial design of language features. We also show how we use a library implementation to test our design.

So far, this effort has involved more than a dozen people, including the father of the STL, Alex Stepanov, but we still consider it research in progress rather than a final design. This design has far fewer concepts than the C++0x design and far simpler language support. The design is mathematically well founded and contains extensive semantic specifications (axioms). It is currently available as a GCC Branch and expected to be part of C++14.

A Standardization Overview (Herb Sutter)

The ISO C++ committee has transitioned to a “decoupled” model where updated versions of the standard are published more frequently, while at the same time major pieces of work can progress and be published independently from the Standard itself and delivered asynchronously in the form of Technical Specifications (TS’s) that are separate from the main Standard and can later be incorporated into the Standard.

In this session, we’ll give a summary of the new features coming in C++14 itself, and then a tour of the seven (7) near-term separate Technical Specifications already underway -- think of these as the "C++14 wave" of deliverables. The topics covered will be:

  • C++14: What’s new in the new standard due this year
  • File System TS: Portable file system access
  • Library Fundamentals TS (small): string_view and optional<>
  • Networking TS (small): IP addresses, URIs, byte ordering
  • Concepts Lite TS: Templates + constraints = ++usability and ++diagnostics
  • Array Extensions TS: Language and library dynamic arrays
  • Concurrency TS: Nonblocking futures (.then, .when_*), executors, and (maybe) await
  • Parallelism TS: A whole new Parallel STL with both parallel and vector execution support

This session will give an overview of each set of features, what it looks like and how to use it, and why it's important for the standard and for your own portable C++ code.

Making Simple Things Simple (Bjarne Stroustrup)

One aim of C++11 (and C++14) was to make simple things simple (without obstructing advanced solutions to the problems faced by experts). This talk examines the role of simple language facilities (such as auto, initializer lists, container algorithms, and range-for) in the overall picture of making C++ easier to use without compromizing generality and perfromance.

Three Cool Things in C++ Concurrency (Herb Sutter)

This session will show three cool and practical concurrency techniques drawn from Herb’s "Effective Concurrency" writing and presented in modern C++. Will there be a lock-free data structure? a technique to eliminate naked threads? a lock ordering discipline? something else? Come see.

A Design Exercise (Bjarne Stroustrup)

A language feature in isolation is boring and useless. This talk explores a set of ideals for a sample library (a simple Matrix with associated operations) and explores the implications in terms of design choices, language features used, and techniques needed.

Panels and Q&A

Each day will set aside liberal time for panel and Q&A discussion with these world-class instructors not available at any other event.

And more!

Don’t miss Stroustrup and Sutter on C++ at EE Live! in spring 2014.