C++20 Concepts: part 4

Gajendra Gulgulia
6 min readDec 12, 2021

In this issue of the concepts tutorial, I’ll discuss in detail about abbreviated function template syntax , constraining auto with abbreviated function template syntax , constraining deduced return type, i.e. constraining the auto return type with concepts.

1. Abbreviated function template syntax in C++20

1.1. Introduction

With the introduction of concepts in C++20, generic program (and here function templates) have changed in meaning and specification. Abbreviated function templates are a part of the change.

C++20 abbreviated function templates in C++20 mean the same to generic functions, what generic lambda expressions in C++14 meant: use of auto in function parameters instead of writing the verbose template syntax . For e.g.

template <typename T>
void foo(T param) { /* do something */ } (1)

in C++20 can be written as

void foo(auto param) { /* do something */ } (2)

without changing the meaning of the function. Here’s what cpp reference page have to say about abbreviated function template syntax:

When placeholder types (either auto …) appear in the parameter list of a function declaration or of a function template declaration, the declaration declares a…

--

--