Abseil C++

An open-source collection of C++ library code designed to augment the C++ standard library

  • Tip of the Week #175: Changes to Literal Constants in C++14 and C++17.
    https://abseil.io/tips/175

    Originally posted as TotW #175 on January 30, 2020

    By James Dennett

    Updated 2020-04-06

    Quicklink: abseil.io/tips/175

    “The only thing that stays the same is change” – Melissa Etheridge

    Overview

    C++ now has some features that can make numeric literals more readable.

    Integer literals can now be written in binary (0b00101010) as well as the decimal (42), hex 0x2A and octal (052) formats that have been supported since the dawn of time.

    Single quotes (’) serve as digit separators, and can be used to group digits in numeric literals of any base (0xDEAD’C0DE).

    Floating point literals can be specified in hex (0x2A0p-4).

    Binary Literals

    Binary literals such as 0b1110’0000 can be more readable than hex (the next best option) when manipulating bit sets or working with low-level protocols. Code that (...)