How to Use Class Template Argument Deduction--Stephan T. Lavavej

Progress.

How to Use Class Template Argument Deduction

by Stephan T. Lavavej

From the article:

Class Template Argument Deduction (CTAD) is a C++17 Core Language feature that reduces code verbosity. C++17’s Standard Library also supports CTAD, so after upgrading your toolset, you can take advantage of this new feature when using STL types like std::pair and std::vector. Class templates in other libraries and your own code will partially benefit from CTAD automatically, but sometimes they’ll need a bit of new code (deduction guides) to fully benefit. Fortunately, both using CTAD and providing deduction guides is pretty easy, despite template metaprogramming’s fearsome reputation!

Word Counting in C++: Implementing a Simple Word Counter--Jonathan Boccara

Useful to learn.

Word Counting in C++: Implementing a Simple Word Counter

by Jonathan Boccara

From the article:

Word counts can reveal information about your code, or make an unknown piece of code more expressive to your eyes.

There are online tools to count words in generic text, but most of those I’ve come across are designed around counting words in text and SEO (Search Engine Optimization). Since analysing source code is not the same thing as analysing the text of a blog post, let’s design a tool fit for our needs of counting words in code. This way, we will be able to make it evolve when we discover new tasks to try with our word counter.

Another reason to write our own word counter is that it will let us practice interface design, and also STL algorithms, which are useful to master for coding in C++.

For this first version of our word counter, the objective will be to put together a working prototype. Then we will improve it over future posts, by adding features and by refining its implementation...

Quick Q: constexpr specifier performance did't meet my expectations in C++

Quick A: a constexpr function does not imply it will be evaluated at compile time.

Recently on SO:

constexpr specifier performance did't meet my expectations in C++

Your constexpr function requires way too much computation to do in a compiler, that's why the compiler chooses to delay it to runtime execution.

You can change this line:

static const auto c_x = c_fun(40);

to:

constexpr auto c_x = c_fun(40);

to see compiler's output. On clang, it tells me:

note: constexpr evaluation hit maximum step limit;
c_x is indeed a compile-time constant, but the compiler can't compute it due to implementation limitation. Note that your function has exponential complexity.

Everything will be fine if you change 40 to some reasonable number, like 10:

constexpr auto c_x = c_fun(10);

C++ Links #6—Bartlomiej Filipek and Wojciech Razik

The next episode of the 'most useful C++ links' is now available:

C++ Links #6

by Bartlomiej Filipek and Wojciech Razik

From the article:

Welcome to new C++ Links - most important and useful articles, podcasts and videos that happen between 6th and 12th of October.

Today you will find a link to Core Guidelines rules about Concepts, a long article about C++17 class template deduction and a video that shows how inline keyword is taken into account by the compiler. At the end, you will also find a bonus!

New Pluralsight Course: Introduction to Data Structures and Algorithms in C++ -- Giovanni Dicanio

A new course was published in the Pluralsight library:

Introduction to Data Structures and Algorithms in C++

by Giovanni Dicanio

From the article:

In this course, you’ll learn how to implement some fundamental data structures and algorithms in C++ from scratch, with a combination of theoretical introduction using slides, and practical C++ implementation code.

No prior data structure or algorithm theory knowledge is required. You only need a basic knowledge of C++ language features.

 

 

JSON for Modern C++ version 3.3.0--Niels Lohmann

Are you using it?

JSON for Modern C++ version 3.3.0

by Niels Lohmann

From the article:

This release adds support for GCC 4.8. Furthermore, it adds a function get_to to write a JSON value to a passed reference. Another topic of this release was the CMake support which has been overworked and documented.

Besides, a lot of bugs have been fixed and slight improvements have been made. All changes are backward-compatible...

std::any: How, when, and why--Casey Carter

Do you use it?

std::any: How, when, and why

by Casey Carter

From the article:

C++17 adds several new “vocabulary types” – types intended to be used in the interfaces between components from different sources – to the standard library. MSVC has been shipping implementations of std::optional, std::any, and std::variantsince the Visual Studio 2017 release, but we haven’t provided any guidelines on how and when these vocabulary types should be used. This article on std::any is the second of a series that examines each of the vocabulary types in turn...

“auto to stick” and Changing Your Style--Jonathan Boccara

What do you think?

“auto to stick” and Changing Your Style

by Jonathan Boccara

From the article:

While performing a code review on a refactoring project, I stumbled upon a change that took a line of code from this state:

Widget myWidget{42};

to that:

auto myWidget = Widget{42};

Well, in the actual case the type wasn’t called Widget and the initialization value wasn’t exactly 42. But that’s the gist of it...