basics

Bitesize Modern C++: std::initializer_list--Glennan Carnie

Do you know how to use initializer lists?

Bitesize Modern C++: std::initializer_list

by Glennan Carnie

From the article:

An aggregate type in C++ is a type that can be initialised with a brace-enclosed list of initialisers. C++ contains three basic aggregate types, inherited from C:

  • arrays
  • structures
  • unions

Since one of the design goals of C++ was to emulate the behaviour of built-in types it seems reasonable that you should be able to initialise user-defined aggregate types (containers, etc.) in the same way...

Bitesize Modern C++: Uniform initialization--Glennan Carnie

Do you know how the uniform initialization?

Bitesize Modern C++: Uniform initialization

by Glennan Carnie

From the article:

C++98 has a frustratingly large number of ways of initialising an object.

(Note: not all these initialisations may be valid at the same time, or at all. We’re interested in the syntax here, not the semantics of the class X)

One of the design goals in C++11 was uniform initialisation syntax...

Bitesize Modern C++: using aliases--Glennan Carnie

Do you know how to use type aliasing?

Bitesize Modern C++: using aliases

by Glennan Carnie

From the article:

In a C++ program it is common to create type aliases using typedef. A type alias is not a new type, simply a new name for an existing declaration. Used carefully, typedef can improve the readability and maintainability of code – particularly when dealing with complex declarations...

Bitesize Modern C++: nullptr--Glennan Carnie

An article about the null value of a pointer:

Bitesize Modern C++: nullptr

by Glennan Carnie

From the article:

What’s the value of a null pointer?

  • 0
  • NULL
  • NUL

No doubt you’ve been involved in the (always heated) discussions about which is the correct one (By the way, if you said NUL you need to take yourself to one side and give yourself a stern talking to)...

C++ User Group Meetings in July

The monthly overview on upcoming C++ User Group Meetings, this time its 18 User Groups who are meeting during summer!

C++ User Group Meetings in July

by Jens Weller

The list of meetings:

7.7 C++ UG Chicago - Memory Management in C++14 and Beyond
8.7 C++ UG San Francisco/ Bay area - HPX, C++ parallel programming framework
8.7 C++ UG Bristol - The Anatomy of Exceptional Engineers
9.7 C++ UG New York - July C++ Meetup
9.7 C++ UG Amsterdam - Hot C++, Part 2
9.7 C++ UG Dresden - Lazy generating non-integral values in range-based for loops
15.7 C++ UG Utah - Embedded Scripting with ChaiScript
15.7 C++ UG Bristol - Save the date
15.7 C++ UG Washington, DC - Q & A / Info Sharing
15.7 C++ UG Düsseldorf - Traveling for C++, a trip report
21.7 C++ UG Berlin - Ingo Josopait - Introducing the Goopax compiler for GPUs and Barb
21.7 C++ UG Portland - PDXCPP July Meeting-- feat. Jon Kalb
22.7 C++ UG San Francisco/ Bay area - Workshop and Discussion Group
23.7 C++ UG Rhein-Neckar - Presenting for Geeks
28.7 C++ UG Cologne - Monthly meeting
29.7 C++ UG Washington, DC - Q & A / Info Sharing
29.7 C++ UG Hamburg - Protocol Buffers
30.7 C++ UG Bremen - C++ Testframeworks

Bitesize Modern C++: enum class--Glennan Carnie

A simple and complete explanation of the enum:

Bitesize Modern C++: enum class

by Glennan Carnie

From the article:

Enumerated types in C++ give a trivial simulation of symbolic types – that is, objects whose instances have unique, human-readable values. In C++ enumerations are essentially named integers that are either assigned values implicitly by the compiler or explicitly by the programmer (or a combination of both)...

The Four Polymorphisms in C++ -- Peteris Krumins

C++ has more than one ways to express polymorphism. Discover the nomenclature and read examples on all of them in the following article :

The Four Polymorphisms in C++

by Peteris Krumins

From the article:

(...) These polymorphisms also go by different names in C++ :

  • Subtype polymorphism is also known as runtime polymorphism.
  • Parametric polymorphism is also known as compile-time polymorphism.
  • Ad-hoc polymorphism is also known as overloading.
  • Coercion is also known as (implicit or explicit) casting.

Nugget: static_assert--Glennan Carnie

A short nugget by Glennan Carnie:

static_assert

by Glennan Carnie

From the article:

C’s assert library is a useful tool for catching invalid invariants (conditions that must hold true in order for your system to operate as specified) in your program. The big problem with assert is that it’s a run-time check; in many cases the best you can do  to recover from an assert failure is restart the system or put it into a quiescent state...

The compiler is to blame for everything -- Andrey Karpov

Many programmers are very fond of blaming the compiler for different errors. Let's talk about it.

The compiler is to blame for everything

by Andrey Karpov

From the article:

When a programmer tells you that the compiler causes an error, it is a lie in 99% of cases. When you start investigating the problem, you usually find out the following reasons:

  • an array overrun;
  • an uninitialized variable;
  • a misprint;
  • a synchronization error in a parallel program;
  • a non-volatile variable used;
  • code leading to undefined behavior;
  • etc.

Quick Q: Why are override and final identifiers with special meaning instead of reserved keywords?

Quick A: To avoid breaking old code, thanks to context-sensitive keywords.

Recently on SO:

Why are override and final identifiers with special meaning instead of reserved keywords?

Both the override specifier and final specifier were added in C++11. They differ from other specifiers added to C++11 such as constexpr and decltype, in that they are not keywords and so are available for use as identifiers:

int main()
{
  int override = 0 ;    // Ok
  int final = 0 ;       // Ok
  //int constexpr = 0 ; // Error
}

They are referred to as identifiers with special meaning, which is covered in the draft C++11 standard section 2.11 [lex.name] (emphasis mine):

The identifiers in Table 3 have a special meaning when appearing in a certain context. When referred to in the grammar, these identifiers are used explicitly rather than using the identifier grammar production. any ambiguity as to whether a given identifier has a special meaning is resolved to interpret the token as a regular identifier.
and Table 3 -- Identifiers with special meaning lists both override and final.

Why did these two specifiers end up being identifiers with special meaning instead of keywords?