PVS-Studio confesses its love for Linux

You will help greatly if you volunteer to help testing the beta-version of PVS-Studio for Linux.

PVS-Studio confesses its love for Linux

by Andrey karpov

From the article:

PVS-Studio is a tool for bug detection in the source code of programs, written in C, C++, and C#. We are looking forward to the moment that we'll have something to present to this world. I hope this article brought some intrigue, and that Linux developers will want to try scanning their projects with PVS-Studio. If you have time and wish to, I invite you to become a part of the beta-tester team.

Const Correctness--Arne Mertz

Do you use const well?

Const Correctness

by Arne Mertz

From the article:

Writing const correct code is about more than using const in a few places and letting the compiler figure out if it makes sense.

There are two components about using the keyword const in C++ code: A syntactic component and a semantic component...

Quick Q: Conditional use of std::lock_guard

Quick A: Use std::unique_lock instead.

Recently on SO:

Conditional use of std::lock_guard

How about this one?

void bar(std::mutex * optionalMutex = nullptr)
{
        auto lockScope = (optionalMutex == nullptr) ?
                           std::unique_lock<std::mutex>()
                         : std::unique_lock<std::mutex>(*optionalMutex);

}

Explanation: You're compiler had trouble with your prior statement because, you can not suddenly change the type of the ternary ? expression, i.e. the literal 0 is not a std::lock_guard and vice versa. So I changed the two branches to the same type, here std::unique_lock<std::mutex> because lock_guard isn't designed be used without a valid mutex. But still prefer std::lock_guard over std::unique_lock in the simpler cases, because it will make you code more readable.

Also your statement wasn't viable for the compiler, i.e. even syntactical correct, because the variable lockScope would only have existed in one branch.

Move safety - know what can be done in the moved-from state--Jonathan Müller

What state is an object after move?

Move safety - know what can be done in the moved-from state

by Jonathan Müller

From the article:

C++ programmers have this notion of exception safety. It is a very useful concept. With it one can easily describe the post-conditions of a function if it throws.

There is another situation where you need to easily describe some post-conditions: when talking about the state of an object after a move operation, i.e. after a move constructor or move assignment operator. I thus want to introduce vocabulary for those post-conditions of the right-hand argument similar to the exception safety of a function: The move safety, if you will.

The exception safety describes the post-conditions of a function if the function throws an exception. Similarly, the move safety describes the post-conditions of the object after a move operation. It thus gives information about what can be done safely with a moved-from object...

C++/Graphics Workshop--Stephanie Hurlburt

Are you interested?

C++/Graphics Workshop

by Stephanie Hurlburt

Description of the event:

Ever been curious about C++ and graphics programming, but not sure where to start?
Maybe you are an artist who'd like to build your own tools. Maybe you're a game developer wishing your games would run faster, or have even better graphics effects. Regardless, knowledge of the way graphics work at a low level is an empowering skill.
We'll be covering real-time graphics with C++/OpenGL as well as raytracing. It'll be aimed at beginners, but everyone is welcome.
This'll be an intimate workshop, meant for around 20 people. We'll give a talk and then walk you through some hands-on examples. Be sure to bring a laptop if you can!

CppCon 2015 Cross-Platform Mobile App Development with Visual C++--Ankit Asthana & Marc Gregoire

Have you registered for CppCon 2016 in September? Don’t delay – Registration is open now.

While we wait for this year’s event, we’re featuring videos of some of the 100+ talks from CppCon 2015 for you to enjoy. Here is today’s feature:

Cross-Platform Mobile App Development with Visual C++

by Ankit Asthana & Marc Gregoire

(watch on YouTube) (watch on Channel 9)

Summary of the talk:

Visual C++ 2015 supports the development of apps for the Windows platform as well as for Android and iOS. A single code base, possibly with a thin platform-specific UI layer, can be compiled to run on Windows, Android, and iOS. The resulting binary can be published to a device and debugged, all from within Visual C++ 2015. This presentation introduces you to such cross-platform mobile app development, including debugging and emulation, and includes a number of demos.

Quick Q: Why two null constructors for std::unique_ptr?

Quick A: The nullptr_t constructor was added later.

Recently on SO:

Why two null constructors for std::unique_ptr?

For (1), consider that it ensures that both the no-arg constructor unique_ptr() and null-pointer constructor unique_ptr(nullptr_t) have the same compile-time guarantees, i.e. both are constexpr. We can see the difference in §20.8.1.2:

constexpr unique_ptr() noexcept;
explicit unique_ptr(pointer p) noexcept;
...
constexpr unique_ptr(nullptr_t) noexcept
: unique_ptr() { }

Why the two were not combined into a single constructor with a default value is likely historical contingency.

With regards to (2), why we should care about constexpr despite having a non-trivial destructor, consider the answer given here:

constexpr constructors can be used for constant initialization, which, as a form of static initialization, is guaranteed to happen before any dynamic initialization takes place.

For example, given a global std::mutex:

std::mutex mutex;

In a conforming implementation (read: not MSVC), constructors of other objects can safely lock and unlock mutex, becuase std::mutex's constructor is constexpr.

CppCon 2015 C++: How I learned to stop worrying and love metaprogramming--Edouard Alligand

Have you registered for CppCon 2016 in September? Don’t delay – Registration is open now.

While we wait for this year’s event, we’re featuring videos of some of the 100+ talks from CppCon 2015 for you to enjoy. Here is today’s feature:

C++: How I learned to stop worrying and love metaprogramming

by Edouard Alligand

(watch on YouTube) (watch on Channel 9)

Summary of the talk:

Horrible software engineering technique conceived in the forge of Hell or the Only True Way of doing C++ in 2015, template metaprogramming and its cohort of companion techniques are sure to create animation in a group of programmers.

What if we were to tell you that an actual software product, actually sold to real customers and in production for now several years has been built on it? What if we were to tell you that a lot of advanced template techniques helped us to build a better software faster?

This talk is all about real life examples of template metaprogramming, why they are useful and when and how you could use them in your own projects.