Articles & Books

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&.

Experimenting with a Proposed Standard Drawing Library for the C++ language -- Eric Mittelette

Today on MSOT:

Experimenting with a Proposed Standard Drawing Library for the C++ language

by Eric Mittelette

From the article:

Back in July, Michael McLaughlin, Herb Sutter, and Jason Zink submitted to the ISO an updated proposal to standardize a 2D Graphics API for the C++ programming language. The ISO C++ Committee will evaluate the proposal for the possible inclusion of these new features in the next versions of the specification.

Given MS Open Tech’s historical interest in cross-platform graphics development, we took a closer look. In an attempt to familiarize with the API from the perspective of a C++ developer, we developed a sample app that we just contributed to Michael’s github repository. In the sections below, we share some salient aspects of how this new crop of Graphics experiences built with “straight” C++ could be written, only a few years from now!
 

 

The compiler can make up its own calling conventions, within limits--Raymond Chen

A new article from the Old New Thing:

The compiler can make up its own calling conventions, within limits

by Raymond Chen

From the article:

There are three parties to a calling convention. The function doing the calling. The function being called. The operating system. The operating system needs to get involved if something unusual occurs, like an exception, and it needs to go walking up the stack looking for a handler...

The lvalue/rvalue metaphor--Joseph Mansfield

Joseph Mansfield discusses about an important topic in C++:

The lvalue/rvalue metaphor

by Joseph Mansfield

From the article:

Every expression in C++ is either an lvalue or an rvalue. This distinction is what makes something like 5 = x; invalid, as the expression 5 is an rvalue expression and so cannot appear on the left of an assignment...

January 2015 C++ Compilers Status--Christophe Riccio

Christophe Riccio gives us an interesting point of view for a library author and shares the latest status of some compilers:

January 2015 C++ Compilers Status

by Christophe Riccio

From the article:

...Finally, a last issue for adopting new C++11 features is simply our own ignorance of which feature is available on all the compilers we support. To resolve that problem, I made the followiong table listing all the C++ features and their support on Clang, GCC, ICC and Visual C++...

for_each_arg -- Eric Niebler

Eric Niebler picked up the Sean Parent's challenge regarding his for_each_argument tweet.

for_each_arg

by Eric Niebler

And after several iterations between Sean and Eric this is the beautiful result:

template<class F, class...Ts>
F for_each_arg(F f, Ts&&...a) {
  return (void)initializer_list<int>{(ref(f)((Ts&&)a),0)...}, f;
}

 

C++11 and 64-bit Issues--Andrey Karpov

Developing 64-bit applications in C/C++ requires much attention from a programmer. There are a number of reasons for 32-bit code to fail to work properly when recompiled for the 64-bit platform. Let's find out if the new features introduced in C++11 have made 64-bit software programmers' life any better and easier.

C++11 and 64-bit Issues

by Andrey Karpov

From the article:

Extensive use of the C++11 language's new constructs in your code doesn't guarantee that you will avoid 64-bit errors. However, the language does offer a number of useful features to help make your code shorter and safer.

A Small Set-Algorithm For Enum Values -- Felix Petriconi

Inspired by Sean Parent's recent Tweet I came up with this idea:

A Small Set-Algorithm For Enum Values

by Felix Petriconi

From the article:

Often we have in our own production code statements like this:

auto predicate = [](State state) {
  return state == MyEnumClass::ValueA ||
         state == MyEnumClass::ValueD ||
         state == MyEnumClass::ValueEWithAVeryLongName;
};

A better readable solution with less typing is described there.