• Home
  • /
  • Blog
  • /
  • And the Five Winners for the “C++20 STL Cookbook” are

August 14, 2022

Today, I want to present the five winners for the pdf of the book “C++20 STL Cookbook” by Bill Weinman.

 CoverBig

To get the book, you had to answer the following question by Bill Weinmann: “What are the major advantages of the C++20 format library over printf and iostream?“. Here are the best five answers. Two answers were almost literally identical, but I had to decide for one of them.

Manali

1. Format () is clean, precise , flexible variadic template function in terms of its usage and code readability.
2. With iostream we use for example: std::cout, std::cin . This use of scope resolution (namespaces) and insertion / extraction operations is overcome with help of format function , improving performance and efficiency.
3. format() function provides type safety ,
Formatting options, supporting classes and objects , positional arguments.

Uzoochogu

 format

Gabriel

Disadvantages:
– not Type safe
– it is not extensible because it only supports a specific number of types.

Advantages:
– Type safe
– now extensible ( yay 😀 )
– readable
– easier to localize/translate

Roberto

printf

 

 

 

 

iostreams

 

 

 

 

format1

 

 

 

 

 

 

format2

 

 

 

 

 

 

 

 

 

 

Demo

Hyper

my answer is that the C++20 format library provides a rich set of formatting options that exceeds even that of prinf. It provides a positional arguments and is extensible to support more values and classes. It is like it was isnpired by Python str.format method.
the C++20 format() function is a variadic template function which provides type safety, along with the performance and efficiency advantages of iostream. the format library also provides vformat(), a type-erased interface that prevents generating multiple instances of complex template function for each combination of arguments.
the make_formate_arge() function creates a type-erased parameter stack to pass to vformat(), which does the heavy lifting of formatting the string. This is how the format() library operates so efficiently.

 

 

 

 

 

Leave a Reply


Your email address will not be published. Required fields are marked

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

Related Posts