...

/

Traits

Traits

Let's learn about the C++ trait idiom.

Let’s discuss the trait idiom, which is an essential idiom in C++. The trait is an important idiom that will provide the base for the upcoming idiom tag dispatching.

Introduction

Traits are class templates that provide the characteristics of a generic type. They can extract one or more characteristics of a class template.

The metafunctions from the type-traits library are typical examples of traits in C++. Here are a few of them:

  • Type checks
  • Type comparisons
  • std::is_base_of
  • Correctness
  • Performance

Code

Access this course and 1400+ top-rated courses and projects.