intermediate

Dive into C++11 (#2) -- Frametime/FPS, constexpr, uniform initialization, and more

Hello again, I’m Vittorio Romeo, a computer science student, hobbyist game developer and C++ enthusiast.

I've uploaded the second episode of "Dive into C++11" on my YouTube channel. You can find the first episode here.

You can find the complete playlist here.

In this episode we will learn more about two previously mentioned new awesome C++11 features: "constexpr" and "uniform initialization syntax".

Most importantly, we will also deal with a very big issue that every game developer must face: FPS/frametime, and how to avoid the game from behaving differently on slower/faster machines.

In addition, we'll also briefly learn about "const-correctness" and using the "noexcept" keyword.

We will analyze the "time-slice" method to allow the game to run smoothly and consistently on every machine.

In the last code segment, we will also "refactor" our code by creating a `Game` class, making our source much easier to read and maintain.

I greatly appreciate comments and criticism, and ideas for future videos/tutorials.

Feel free to fork the game's source code at: https://github.com/SuperV1234/Tutorials

CppQuiz.org officially launched -- Anders Schau Knatten

Anders Schau Knatten recently launched the new site CppQuiz.org inspired largely by Olve Maudal's C++ pub quizzes. So grab a refreshing beverage, pull up a chair, and try a few to start off the first week of December...

CppQuiz.org officially launched!

by Anders Schau Knatten

From the announcement:

What is it

CppQuiz.org is (as you might have guessed by now) an online C++ quiz. Each question is a full C++ program, and you are to figure out what its output is. I stole this format from Olve Maudal's pub quizzes, but with one major difference: While his quizzes are about what happens on his computer (which is very interesting for a more interactive format), CppQuiz.org asks about what the standard mandates the output to be. If the example code doesn’t compile, or has unspecified/undefined behaviour, you answer that.

The site will just keep throwing questions at you (training mode), optionally giving you a hint and finally give you a full explanation of the answer, with references to the C++11 standard. If you want, you can however start a new quiz (quiz mode), and get a fixed number of questions. At the end you get a score, and a link to give your friends to see if they can beat you. Neither mode requires you to register or log in.

How you can help

If you like the quiz and want to help, there are many ways to do so:

  • Create your own questions, as many have done
  • Help improve the design (pull requests, e-mail, Twitter)
  • Help improve the functionality (pull requests, e-mail, Twitter)
  • Any other feedback (comments to this post, e-mail, Twitter)

Quick Q: When do you need to declare a variable constexpr? -- StackOverflow

Quick A: When you want to use the variable in a way that requires its value to be known at compile time.

Here's a short nugget that helps demonstrate the meaning of constexpr:

Why is constexpr required even though member function is constexpr?

The following does not compile unless I put constexpr before initializer_list:

constexpr std::initializer_list<int> il = {
    1, 2, 3, 4, 5, 6, 7, 8, 9, 10
};
std::array<int, il.size()> a;

But initializer_list size is constexpr:

constexpr size_type size() const;

What are inline namespaces good for? -- StackOverflow

Quick A: For source-level library versioning.

A StackOverflow classic:

What are inline namespaces for?

C++11 allows inline namespaces, all members of which are also automatically in the enclosing namespace. I cannot think of any useful application of this -- can somebody please give a brief, succinct example of a situation where an inline namespace is needed and where it is the most idiomatic solution?

(Also, it is not clear to me what happens when a namespace is declared inline in one but not all declarations, which may live in different files. Isn't this begging for trouble?)

Concept Checking in C++11 -- Eric Niebler

While we're waiting for Concepts Lite, Eric shows how we can already do quite a bit in C++11 while planning for a transition to language support when it's available.

Concept Checking in C++11

by Eric Niebler

From the article:

This post describes some utilities I’ve recently developed for doing concept checking in C++11. These utilities are part of an ongoing project to reimplement ranges, also for C++11, but I think the concept checking utilities are useful and interesting in their own right...

Stroustrup & Sutter on C++: Mar 31 - Apr 1, San Jose, CA, USA

eelive.PNGFor the first time in several years, Bjarne Stroustrup and Herb Sutter will hold a two-day seminar on C++

Super C++ Tutorial: Stroustrup & Sutter on C++

EE Live!
March 31 - April 3, 2014
San Jose, CA, USA

Are you a serious C++ developer? The two-day Super C++ Tutorial, taught by Herb Sutter and Bjarne Stroustrup, the creator of C++, is designed for active C++ developers, embedded systems developers, and anybody who works with the language on a regular basis and wants to write faster, more efficient code for applications ranging from data centers to mobile platforms where all-day battery life is key.

We invite you to spend two insightful and informative days as the instructors present the most important things C++ developers need to know in 2014. The two days are designed to cover a balanced curriculum of information: useful for C++ developers at any level, with helpful information whether you’ve only used C++ for a year or two or are a top C++ guru; balanced between language and standard library topics; covering today’s modern techniques and best practices together with forward-looking information about new features coming and expected to be broadly available in the next year; panels where both speakers share their insights and perspectives with each other and answer your questions; and much more, with the deep context and expertise that these instructors uniquely bring.

Quick Q: Why is std::vector contiguous? -- StackOverflow

Quick A: Because if you're serious about performance, you'll often (not always) use contiguous arrays.

From SO:

Why is std::vector contiguous?

Besides the fact that the standard defines it to be contiguous, why is std::vector contiguous?

If it runs out of space, it needs to reallocate a new block and copy the old block to the new one before continuing.

What if it wasn't contiguous? When the storage fills up, it would just allocate a new block and keep the old block. When accessing through an iterator, it would do simple >, < checks to see which block the index is in and return it. This way it doesnt need to copy the array every time it runs out of space.

Would this really work/be better? or am i missing something?

Type Erasure, Part 1 -- Andrzej KrzemieĊ„ski

What is this "type erasure" thing you speak of? It's not something at the other end of a pencil (remember those?) but a way to hold an object without knowing its exact type. Andrzej explains:

Type Erasure, Part 1

by Andrzej Krzemieński

From the article:

Have you ever came across term type erasure in C++? This “pattern” or “technique” is growing more and more popular. In this post I will try to describe what it is. Note that it is something different than a similar term in Java.

What does type encode?

Let’s start with describing the opposite of type erasure. We could call such situation “type-full-ness”. Forget the term though, let me illustrate what I mean with an example. ...

Core C++ #10 -- Stephan T. Lavavej

core-10.PNGAccompanying today's release of the VC++ CTP, there is a new talk by Stephan T. Lavavej available covering several major C++11 and draft C++14 features that are of likely interest to C++ developers using any compiler.

Core C++, 10 of n (Nov 2013 CTP)

by Stephan T. Lavavej

From the summary:

In part 10, STL explores the new features in the Visual C++ Compiler November 2013 CTP (Community Technology Preview), in addition to the features that were added between VC 2013 Preview and RTM.

Features included in the November CTP ( generic lambdas!!! Smiley ):

C++11, C++14, and C++/CX features:

  • Implicit move special member function generation (thus also completing =default)
  • Reference qualifiers on member functions (a.k.a. "& and && for *this")
  • Thread-safe function local static initialization (a.k.a. "magic statics")
  • Inheriting constructors
  • alignof/alignas
  • __func__
  • Extended sizeof
  • constexpr (except for member functions)
  • noexcept (unconditional)
  • C++14 decltype(auto)
  • C++14 auto function return type deduction
  • C++14 generic lambdas (with explicit lambda capture list)
  • (Proposed for C++17) Resumable functions and await