April 2018

Quick Q: Why does unary operator & not require a complete type?

Quick A: It only need to take the address.

Recently on SO:

Why does unary operator & not require a complete type?

What if stru has overloaded operator&()?

Then it is unspecified whether the overload will be called (See Oliv's comment for standard quote).

How could unary operator & does not require a complete type?

That's how the standard has defined the language. The built-in address-of operator doesn't need to know the definition of the type, since that has no effect on where to get the address of the object.

One consideration for why it is a good thing: Compatibility with C.

Trip report: Winter ISO C++ standards meeting (Jacksonville)--Herb Sutter

Lots of things happened.

Trip report: Winter ISO C++ standards meeting (Jacksonville)

by Herb Sutter

From the article:

On Saturday March 17, the ISO C++ committee completed its winter meeting in Jacksonville, Florida, USA, hosted with thanks by the Standard C++ Foundation and Perennial. We had some 140 people at the meeting, representing 8 national bodies. As usual, we met for six days Monday through Saturday, including all evenings...

Quick Q: Why does shared_ptr needs to hold reference counting for weak_ptr?

Quick A: To know when to deallocate the control block.

Recently on SO:

Why does shared_ptr needs to hold reference counting for weak_ptr?

The reference count controls the lifetime of the pointed-to-object. The weak count does not, but does control (or participate in control of) the lifetime of the control block.

If the reference count goes to 0, the object is destroyed, but not necessarily deallocated. When the weak count goes to 0 (or when the reference count goes to 0, if there are no weak_ptrs when that happens), the control block is destroyed and deallocated, and the storage for the object is deallocated if it wasn't already.

The separation between destroying and deallocating the pointed-to-object is an implementation detail you don't need to care about, but it is caused by using make_shared.

If you do

shared_ptr<int> myPtr(new int{10});

you allocate the storage for the int, then pass that into the shared_ptr constructor, which allocates storage for the control block separately. In this case, the storage for the int can be deallocated as early as possible: as soon as the reference count hits 0, even if there is still a weak count.

If you do

auto myPtr = make_shared<int>(10);

then make_shared might perform an optimisation where it allocates the storage for the int and the control block in one go. This means that the storage for the int can't be deallocated until the storage for the control block can also be deallocated. The lifetime of the int ends when the reference count hits 0, but the storage for it is not deallocated until the weak count hits 0.

Is that clear now?

Announcing Meeting C++ 2018

The details for Meeting C++ 2018:

Announcing Meeting C++ 2018

by Jens Weller

From the article:

Meeting C++ returns with its 2018 conference edition! Like in the previous years, we'll be meeting in Berlin from the 15. - 17th November!

Call for Talks will start soon, just as last year, Meeting C++ 2018 has a track for new speakers!

GoingNative 65: ISO C++ @ Jacksonville Debriefing--Augustin Popa

Another is out!

GoingNative 65: ISO C++ @ Jacksonville Debriefing

by Augustin Popa

From the video:

We are back quickly after our last episode to go over the latest news from the ISO C++ Standards Committee meeting in Jacksonville, Florida! C++20 planning is well on its way now as Steve Carroll chats with Gabriel Dos Reis and Gor Nishanov about new progress with C++ Modules, Coroutines, and more!

Some coroutine-related papers accepted for a future version of the C++ standard (provides more context on the code shared in the video):

  • Symmetric control transfer
  • Parameter preview

C++ Modernization Brochure--Don Tait

Interested?

C++ Modernization Brochure

by Don Tait

From the article:

New releases of the C++ language maintain incredibly strong backwards compatibility, making it easy to keep older C++ code working properly as standards march forward. C++11, C++14, and C++17 have transformed the C++ language in ways that make it as programmer-friendly as more recent languages but with many essential benefits that continue to make it the best choice for the most demanding software-engineering projects.

Modernizing your C++ may be the best way to both improve your team’s efficiency as well as future-proof your software investment. KDAB has broad, deep experience delivering cost-effective, long-term, pragmatic solutions that modernize existing C++ codebases without losing functionality during the process.

Download our brochure to find out more...

Using Parallel Without a Clue: 90x Performance Loss Instead of 8x Gain--"No Bugs" Hare

Be careful.

Using Parallel <algorithm> Without a Clue: 90x Performance Loss Instead of 8x Gain

by "No Bugs" Hare

From the article:

With C++17 supporting1 parallel versions of the std:: algorithms, there are quite a few people saying “hey, it became really simple to write parallel code!”.

Just as one example, [MSDN] wrote: “Only a few years ago, writing parallel code in C++ was a domain of the experts.” (implying that these days, to write parallel code, you don’t need to be an expert anymore).

Inquisitive hare:
“I made an experiment which demonstrates Big Fat Dangers(tm) of implying that parallelization can be made as simple as just adding a policy parameter to your std:: call.
I always had my extremely strong suspicions about this position being deadly wrong, but recently I made an experiment which demonstrates Big Fat Dangers(tm) of implying that parallelization can be made as simple as just adding a policy parameter to your std:: call...

C++Now Announces Opening Keynote by Lisa Lippincott

C++Now 2018 will be held in Aspen, May 6–11, 2018.

C++Now 2018 Opening Keynote is Lisa Lippincott

From the announcement:

Lisa approaches languages from a mathematical point of view and thinks deeply on the meaning of programming. In this presentation [The Shape of a Program], she will encourage us to apply topology, the fundamental mathematics of space, as a way of looking at a program.

We expect C++Now to sell out again. Register immediately so you won’t miss out.