March 2018

The “unsigned for value range” antipattern--Arthur O’Dwyer

What do you think?

The “unsigned for value range” antipattern

by Arthur O’Dwyer

From the article:

Background: Signed Integers Are (Not Yet) Two’s Complement
At the WG21 committee meeting which is currently underway in Jacksonville, JF Bastien will be presenting a proposal to make C++’s int data type wrap around on overflow. That is, where today the expression INT_MAX + 1 has undefined behavior, JF would like to see that expression formally defined to come out equal to INT_MIN...

wxWidgets 3.0.4 Released

The wxWidgets team is pleased to announce a new release of our open source framework for the development of native cross-platform applications in C++.

wxWidgets Release 3.0.4

by the wxWidgets team

About the release:

wxWidgets 3.0.4 is a stable bug fix release in 3.0 branch.

More information is available at wxWidgets home page and in the online documentation.

Announcing the Meeting C++ employer listing

News from Meeting C++: the job section features now a listing of C++ employers, which support Meeting C++. Also you can post your own jobs now at Meeting C++!

The Meeting C++ employer listing is online

by Jens Weller

From the article:

With this week, a feature of the old website returns: the Meeting C++ employer listing. So companies with open C++ positions get a permanent representation at Meeting C++ with their profile and contact information.

String’s competing constructors--Andrzej Krzemieński

A tough problem.

String’s competing constructors

by Andrzej Krzemieński

From the article:

Let’s start with the problem. I want to check whether a program received a text message that consists of four consecutive zeroes. Not '0', but the numeric zero. I will create a constant std::string representing the special sequence and compare the messages (also stored as std::strings) I receive...

POCO Release 1.9.0 Available

POCO 1.9.0 is now available:

POCO Release 1.9.0 available

by POCO Team

About the release

POCO C++ Libraries release 1.9.0 is available. Major new features include additional text encodings, available in the Poco::Encodings library, and support for Internationalized Domain Names in the Poco::Net::DNS class.

See the CHANGELOG for the full list of all 20+ changes. Upgrading to this release is recommended.

 

Simplify code with 'if constexpr' in C++17--Bartlomiej Filipek

With examples.

Simplify code with 'if constexpr' in C++17

by Bartlomiej Filipek

From the article:

Before C++17 we had a few, quite ugly looking, ways to write static if (if that works at compile time) in C++: you could use tag dispatching or SFINAE (for example via std::enable_if). Fortunately, that’s changed, and we can now take benefit of if constexpr!

Let’s see how we can use it and replace some std::enable_if code.

Quick Q: What is a non-trivial constructor in C++?

Quick A: All constructors that you define are not trivial.

Recently on SO:

What is a non-trivial constructor in C++?

In simple words a "trivial" special member function literally means a member function that does its job in a very straightforward manner. The "straightforward manner" means different thing for different kinds of special member functions.

For a default constructor and destructor being "trivial" means literally "do nothing at all". For copy-constructor and copy-assignment operator, being "trivial" means literally "be equivalent to simple raw memory copying" (like copy with memcpy).

If you define a constructor yourself, it is considered non-trivial, even if it doesn't do anything, so a trivial constructor must be implicitly defined by the compiler.

In order for a special member function to satisfy the above requirements, the class must have a very simplistic structure, it must not require any hidden initializations when an object is being created or destroyed, or any hidden additional internal manipulations when it is being copied.

For example, if class has virtual functions, it will require some extra hidden initializations when objects of this class are being created (initialize virtual method table and such), so the constructor for this class will not qualify as trivial.

For another example, if a class has virtual base classes, then each object of this class might contain hidden pointers that point to other parts of the very same object. Such a self-referential object cannot be copied by a simple raw memory copy routine (like memcpy). Extra manipulations will be necessary to properly re-initialize the hidden pointers in the copy. For this reason the copy constructor and copy-assignment operator for this class will not qualify as trivial.

For obvious reasons, this requirement is recursive: all subobjects of the class (bases and non-static members) must also have trivial constructors.

A Foolish Consistency--Jon Kalb

A very interesting article that we should all read.

A Foolish Consistency

by Jon Kalb

From the article:

Ralph Waldo Emerson famously said, “A foolish consistency is the hobgoblin of little minds, adored by little statesmen and philosophers and divines.” I don’t think he was talking about code, but that statement couldn’t be more relevant to software engineers.

I’ve experienced a scenario like this a number of time in my career:

I’m sharing a new approach to writing code that offers some clear improvements to what we’ve been doing. Perhaps it is more readable, more efficient, or safer. But the response that I hear from colleagues is, “But we can’t do that here. We have <some large number> lines of code where we didn’t do it that way, so it wouldn’t be consistent.”

C++17 Features, in easy to understand before/after tables -- Tony Van Eerd

Results of a recent survey suggest that many devs have a hard time keeping up with changes between each rev of C++.

C++17 before and after table

by Tony Van Eerd

About the article:

Here's a collection of the major changes between C++14 and C++17, with example code for each - typically showing how it may have been written before C++17, and how it can now be written with the new C++17 feature(s).