Page Collection for ^2014-11

2014-11-12 CPlusPlus11

The deprecated attribute

To mark an entity as deprecated the attribute deprecated is introduced. The idea is to be able to mark things, although they are still working, that their use are being discouraged for some reason. The thought goes to things that will be removed in future releases but it is of course not limited to that.

This is different to most other C++-1y features a compile time only feature. It will produce a warning when the code is compiled. That is it.

The syntax is like this:

[[deprecated]]
int func(int i)
{
   ...

You can even add an explanation to why this function is deprecated and this string will be shown in the warning message by the compiler.

[[deprecated("Don't use this please, we are going to remove this next release or so")]]
int old(int i)
{
   ...

Most entities can be marked as deprecated this way. Here are some examples.

class [[deprecated]] C
{
   ...

class C2
{
public:
   [[deprecated]]
   int func(...
   ...

2014-11-17 CPlusPlus11

Binary Literals

One tiny(!?) extension that comes with C++14 is binary literals. You can now write them by prefixing the binary number with 0b. This is a well known syntax from other languages and in fact has been around a while even as a gcc extension. So you might not even recognize this as new feature.

Anyway, it looks like this:

   int b1 = 0b10;
   int b2 = 0B1010;     // Capital B is OK too!

It goes well with digit separators too. You can write:

   int b3 = 0b1010'1010;
   int b4 = 0B010'101'010;

2014-11-22 CPlusPlus11

Digit Separators

When I talked about the binary literals recently I also mentioned digit separators. I thought it was part of C++0x but apparently it is also a new C++1y feature that I have not mentioned yet. Sorry for that. There are so many features so I'm getting confused. ;-) Time to change that then.

Anyway, digit separators is a way to write big numbers so they are easier to read for humans. The apostrophe character is what is used to group or separate digits in a number. It can look like this:

   int decimal = 4'096;
   int binary = 0b0001'0000'0000'0000;
   int hexadecimal = 0x10'00;
   int octal = 0'10'000;
   double x = 1.234'567'890e-19;

Look how the apostrophe neatly groups the digits in the way we are use to see them.

The position of the apostrophe can however be anywhere in the number. It does not have to be according to the radix or any other normal way numbers are written out there in real life. It can be used in any way you like. The later is probably a bad idea but, who knows, there might be cases where it can be put to good use.