basics

Still Comparing "this" Pointer to Null?--Dmitry Meshcheryakov

The article explains why one must never use the (this == 0) expression. It's a very bad code. It being able to work at times doesn't mean anything. By writing (this == 0), you let undefined behavior into your program.

Still Comparing "this" Pointer to Null?

by Dmitry Meshcheryakov

From the article:

In the same way the compiler can optimize the code comparing "this" pointer to null. According to the Standard, this cannot be null and therefore the checks and the corresponding code branches can be eliminated, which will greatly affect the code dependent on the comparison of "this" pointer to null. The compiler has a full right to "break" (actually just break it further) the code CWindow::GetSafeHandle() and generate machine code which doesn't contain the comparison and only reads the class field all the time.
...
GOOD LORD, the "this" pointer equals 0x00000004 on entering the method when compiled in Visual C++ 9, as the pointer initially set to null is adjusted so that it points to the beginning of a subobject of the corresponding class.

No need to square, sum, and sqrt manually anymore--Indi

A useful remainder for programmers, the std::hypot function:

No need to square, sum, and sqrt manually anymore

by Indi

From the article:

I hang out a lot with engineers and game programmers, so that means I tend to see a lot of code dealing with physics problems. One of the most commonly used bits of code in both domains has to be the Euclidean distance equation. However, few programmers realize that that equation is a lot easier than it used to be...

C++ User Group Meetings in February

New month, and a few more C++ User Group Meetings:

C++ User Group Meetings in February

by Jens Weller

From the article:

Again an overview on the upcoming meetings of C++ User Groups. This time, its February again, the shortest, and in a lot of places coldest month of the year. Still, 19 C++ User Groups have already...

The Meetings:

4.2 C++ UG Saint Louis - DD Part 2 - Lambdas
7.2 C++ UG Italy - Pordenone
11.2 C++ UG Utah - Asynchronous Messaging with ØMQ
11.2 C++ UG San Francisco/ Bay area - CopperSpice
11.2 C++ UG Santa Barbara - Introduction to OpenGL with SDL
12.2 C++ UG Dresden - Clean code in asynchronous Programming
12.2 C++ UG Wroclaw - Databases & C++: SOCI, boost::python
16.2 C++ UG Denver - Denver Tech Center C++ Developers
16.2 C++ UG Austin - North Austin Monthly C/C++ Pub Social
17.2 C++ UG Berlin - First meeting at think-cell
18.2 C++ UG Bristol - Kevlin Henney: Making Steaks from Sacred Cows
18.2 C++ UG Düsseldorf - Treffen der C++ User Gruppe NRW
18.2 C++ UG Hamburg - Treffen der C++ User Gruppe Hamburg
19.2 C++ UG Ruhrgebiet - February C++ Meetup in the Ruhr area
21.2 C++ UG Pune, India - Introduction to Concurrency and Memory Models
24.2 C++ UG Warsaw - Overload resolution oraz Zakamarki C++
24.2 C++ UG Edinburgh - First Meeting
25.2 C++ UG San Francisco/ Bay area - Workshop and Discussion Group
26.2 C++ UG Munich - "Dreaming of Names" and "A short (and practical) introduction to

Know your libraries -- Arne Mertz

Prefer standard library over handcrafted logic/algorithm.

Know your libraries

by Arne Mertz

From the article:

I often see people use handcrafted loops or write weird workarounds for stuff the standard library has already taken care of. This does not only apply for standard library features but also for any other library, like Boost, other third party libraries and the libraries the code belongs to. That is bad for several reasons, and I am going to lay out what I think every developer should be required to do before he writes production code.

Two fundamental implementations for one conceptual object -- Mark Isaacson

From the Modern Maintainable Code blog:

Two fundamental implementations for one conceptual object

by Mark Isaacson

From the article:

This is the third article of a series on code reuse. This article discusses how to select between implementations of an object based on patterns in type information. The article uses std::unique_ptr's deleter as a practical case study.

You can find the previous article of the series here (which discusses the analogous problem as it pertains to functions), and the prelude to the next article, which looks at the same problem with one caveat: designing it so that some, but not all, of the methods will be implemented the same way no matter what types you instantiate the object with, here.

Yes, we must replace it++ with ++it--Andrey Karpov

I decided to find out if there is practical sense in writing ++iterator instead of iterator++ when handling iterators.

Is it reasonable to use the prefix increment operator ++it instead of postfix operator it++ for iterators?

by Andrey Karpov

From the article:

I will always write ++it. I did so before but I did it "just in case". Now I can see how useful it is because I regularly launch debug versions. In general, of course, ++it has a very slight influence on the running time. But if I don't make such small optimizations in different places of the code, it will be too late and the profiler won't help me. Bottlenecks will be spread throughout the code.

 

To Be or Not to Be (an Iterator) -- Eric Niebler

Eric Niebler gives in his recent blog post insights about iterators

To Be or Not To Be (an Iterator)

by Eric Niebler

From the article:

Way back in 1999, when the ink on the first C++ standard was still damp, Herb Sutter posed a GoTW puzzler in the still extant C++ Report (RIP): When Is a Container Not a Container? In that article, Herb described the problems of the now-infamous vector<bool>. According to the standard’s own container requirements, vector<bool> is not a container.

In a nutshell, it’s because vector<bool>‘s iterators claim to be random-access, but they’re not. Random-access iterators, when you dereference them, must return a real reference. They can only do that if the thing they point to really exists somewhere. But the bool that a vector<bool>::iterator points to does not exist anywhere. It’s actually a bit in a packed integer, and dereferencing a vector<bool>‘s iterator returns an object of some type that merely acts like a bool& without actually being a bool&.

A Casting Show -- Arne Metz

In this next article Arne Mertz describes different type casts.

A Casting Show

by Arne Mertz

From the article:

In C++ there are two ways of type conversions: implicit and explicit type conversions. The latter are called type casts and they are what this post is about.

Testdriven C++ with Catch

A new video from Meeting C++ 2014:

Testdriven C++ with Catch

by Phil Nash

From the talk description:

C++ has been notorious for being a second class citizen when it comes to test frameworks. There are plenty of them but they tend to be fiddly to set-up and ceremonious to use. Many of them attempt to follow the xUnit template without respect for the language environment they are written for. Catch is an attempt to cut through all of that...