Articles & Books

Abseil’s String Utility APIs—Tom Manshreck

Abseil's C++ Tips of the Week for January 26th

Abseil's String Utility APIs

by Tom Manshreck, Abseil Tech Writer

About the article:

Abseil provides many important string utilities such as StrCat(), StrSplit() and StrJoin(). Read the tips that introduced these APIs at Google and explain how to use them now at https://abseil.io/tips/3  https://abseil.io/tips/10 , https://abseil.io/tips/36  and https://abseil.io/tips/59.

C++17: Initializers for if & switch statements—Marc Gregoire

Small reminder:

C++17: Initializers for if & switch statements

by Marc Gregoire

From the article:

Two small, but very useful C++17 features are initializers for if and switch statements. These can be used to prevent polluting the enclosing scope with variables that should only be scoped to the if and switch statement. The for statement already supports such initializers since the beginning...

Quick Q: Is (4 > y > 1) a valid statement in C++? How do you evaluate it if so?

Quick A: This is not a valid statement.

Recently on SO:

Is (4 > y > 1) a valid statement in C++? How do you evaluate it if so?

The statement (4 > y > 1) is parsed as this:

((4 > y) > 1)

The comparison operators < and > evaluate left-to-right.

The 4 > y returns either 0 or 1 depending on if it's true or not.

Then the result is compared to 1.

In this case, since 0 or 1 is never more than 1, the whole statement will always return false.

Pimpl vs Abstract Interface - a practical tutorial—Bartlomiej Filipek

In the article we describe how to limit compilation dependencies. Two methods are discussed: pimpl approach and via abstract interfaces

Pimpl vs Abstract Interface - a practical tutorial

by Bartlomiej Filipek

From the article:

In the post I covered the pimpl pattern. I discussed the basic structure, extensions, pros and cons and alternatives. Still, the post might sound a bit “theoretical”. Today I’d like to describe a practical usage of the pattern. Rather than inventing artificial names like MyClass and MyClassImpl you’ll see something more realistic: like FileCompressor or ICompressionMethod.

How a weak_ptr might prevent full memory cleanup of managed object—Bartlomiej Filipek

Tricky weak_ptr and shared_ptr interaction:<img alt="" data-cke-saved-src="https://2.bp.blogspot.com/-2XIQxeCUBFc/Wi2JGz_EcXI/AAAAAAAADNU/vEkN6ZtXR-Yon5YuZWBxk-6kjmHD1011ACLcBGAs/s1600/control_block.png" src="https://2.bp.blogspot.com/-2XIQxeCUBFc/Wi2JGz_EcXI/AAAAAAAADNU/vEkN6ZtXR-Yon5YuZWBxk-6kjmHD1011ACLcBGAs/s1600/control_block.png" right;"="" style="float: right; width: 230px; height: 199px;">

How a weak_ptr might prevent full memory cleanup of managed object

by Bartlomiej Filipek

From the article:

It appears that in some cases memory allocated for the object controlled by smart_ptr might not be released until all weak pointers are also ‘dead’.

C++ Comma Operator—Ivan Sanz

It needs to be used carefully, but has its uses.

C++ Comma Operator

by Ivan Sanz

From the article:

Comma operator has been with us for a long time. First seen in C spec and improved with custom overloads in C++, it quickly became one of those hidden things you shouldn’t use.
Most C/C++ books avoid speaking about goto the same way they do about comma operator. This is not fair, as both of them can be used properly on certain cases. Let’s speak about that...

C++ Status at the end of 2017

Bartek's non-official year report

C++ Status at the end of 2017

by Bartlomiej Filipek

From the article:

Four things that I’d like to emphasize for the year:

  • C++17 and the stable progress of the standardization
  • Transparency of the Committee and compiler vendors
  • Community is growing!
  • More tools!

The Pimpl Pattern - what you should know—Bartlomiej Filipek

A good sum up.

The Pimpl Pattern - what you should know

by Bartlomiej Filipek

From the article:

Have you ever used the pimpl idiom in your code? No matter what’s your answer read on smile

In this article I’d like to gather all the essential information regarding this dependency breaking technique. We’ll discuss the implementation (const issue, back pointer, fast impl), pros and cons, alternatives and also show examples where is it used. You’ll also see how modern C++ can change this pattern. Moreover, I hope you’ll help me and provide your examples...